﻿using BarcodeDelay.bean;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BarcodeDelay.business
{
    public class JTDelayHelper
    {
        private static JTDelayHelper instance;
        public static JTDelayHelper Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new JTDelayHelper();
                }
                return instance;
            }
        }
        public bool isSite(string strSiteName)
        {
            bool isSite = true;
            if (strSiteName.Contains("集散") || strSiteName.Contains("转运中心"))
            {
                isSite = false;
            }
            return isSite;
        }

        public bool isCurSiteArrivalDelay(DateTime jtArrivalSiteTime, DateTime jtShouldArrivalTime, out string delayTime)
        {
            delayTime = "";
            bool isArrivalDelay = false;
            try
            {
                if (jtArrivalSiteTime > jtShouldArrivalTime)
                {
                    isArrivalDelay = true;
                    TimeSpan ts = jtArrivalSiteTime - jtShouldArrivalTime;
                    string outputStr = string.Format("{0}天{1}小时", ts.Days, ts.Hours);
                    delayTime = outputStr.ToString();
                    return isArrivalDelay;
                }
            }
            catch (Exception ex)
            {

            }
            return isArrivalDelay;
        }

        public bool getTimeBeanByTime(string key, TimeSpan tsArrival, out TimeBean timeBean, Hashtable htDbgBeans, string siteCode)
        {
            bool res = false;
            timeBean = new bean.TimeBean();
            try
            {
                DbgBean dbgBean;
                if (htDbgBeans.ContainsKey(siteCode))
                {
                    dbgBean = (DbgBean)htDbgBeans[siteCode];
                    if (dbgBean != null)
                    {
                        if (siteCode == dbgBean.ArrivalNetworkCode)
                        {
                            if (dbgBean.actualArrivalTime < dbgBean.plannedArrivalTime)
                            {
                                tsArrival = new TimeSpan(dbgBean.plannedArrivalTime.Hour, dbgBean.plannedArrivalTime.Minute, 0);
                            }
                            else
                            {
                                tsArrival = new TimeSpan(dbgBean.actualArrivalTime.Hour, dbgBean.actualArrivalTime.Minute, 0);
                            }
                        }

                        if (siteCode == dbgBean.DepNetworkCode)
                        {
                            int a = 0;
                            /*if (dbgBean.actualArrivalTime < dbgBean.plannedArrivalTime)
                            {
                                tsArrival = new TimeSpan(dbgBean.plannedArrivalTime.Hour, dbgBean.plannedArrivalTime.Minute, 0);
                            }
                            else
                            {
                                tsArrival = new TimeSpan(dbgBean.actualArrivalTime.Hour, dbgBean.actualArrivalTime.Minute, 0);
                            }*/
                        }
                    }


                }

                ArrayList arListTimeBeans = JTTimeEffi.Instance.m_ht_effibeans[key] as ArrayList;
                TimeSpan tsMin = new TimeSpan(23, 23, 23);
                TimeBean curTimeBean = new bean.TimeBean();
                foreach (TimeBean bean in arListTimeBeans)
                {

                    string endTime = bean.endArrival;
                    if (endTime == "")
                    {
                        continue;
                    }
                    int hour = 0;
                    int minute = 0;
                    int seconds = 0;
                    if (!endTime.Contains(":"))
                    {
                        continue;
                    }
                    curTimeBean = bean;
                    utility.Utility.getSepTime(endTime, out hour, out minute);
                    TimeSpan tsEnd = new TimeSpan(hour, minute, seconds);
                    if (tsEnd < tsArrival)
                    {
                        continue;
                    }
                    TimeSpan tsDiff = tsEnd - tsArrival;
                    if (tsDiff < tsMin)
                    {
                        tsMin = tsDiff;
                        timeBean = bean;
                        res = true;
                    }

                }
                if (!res && arListTimeBeans.Count > 0)
                {
                    timeBean = curTimeBean;
                }

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("getTimeBeanByTime ex:" + ex.ToString());
            }

            return res;

        }


        public int getAssignAddDays(RoadInfo roadSite)
        {
            int addDays = 0;

            try
            {
                string key = roadSite.jtSiteName + "-" + roadSite.jtNextStopName;
                string keyArrCode = "";
                string keyDesCode = "";
                if (JTTimeEffi.Instance.m_ht_site_map.ContainsKey(roadSite.jtSiteName))
                {
                    keyArrCode = JTTimeEffi.Instance.m_ht_site_map[roadSite.jtSiteName] as string;
                }
                if (JTTimeEffi.Instance.m_ht_site_map.ContainsKey(roadSite.jtNextStopName))
                {
                    keyDesCode = JTTimeEffi.Instance.m_ht_site_map[roadSite.jtNextStopName] as string;
                }
                key = keyArrCode + "-" + keyDesCode;
                if (!JTTimeEffi.Instance.m_ht_effibeans.ContainsKey(key))
                {
                    return addDays;
                }
                ArrayList arListTimeBeans = JTTimeEffi.Instance.m_ht_effibeans[key] as ArrayList;

                TimeSpan tsMin = new TimeSpan(23, 23, 23);
                TimeBean curTimeBean = new bean.TimeBean();
                foreach (TimeBean bean in arListTimeBeans)
                {
                    string endTime = bean.endArrival;
                    if (endTime == "")
                    {
                        continue;
                    }
                    int hour = 0;
                    int minute = 0;
                    int seconds = 0;
                    if (!endTime.Contains(":"))
                    {
                        continue;
                    }
                    curTimeBean = bean;
                    addDays = bean.assignAddDays;

                }

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("getAssignAddDays ex:" + ex.ToString());
            }

            return addDays;

        }


        public bool noMapBingoJudge(RoadInfo roadSite)
        {
            bool isDelay = false;
            try
            {
                DateTime dtArrival = roadSite.jtArrivalTime;
                DateTime dtDep = roadSite.jtDepTime;
                TimeSpan tspan = dtDep - dtArrival;
                if (dtArrival.Year == 1)
                {
                    return isDelay;
                }
                if (tspan.Hours > 23)
                {
                    isDelay = true;
                    roadSite.jtDelaySite = roadSite.jtSiteName;
                    roadSite.jtDelayTime = tspan.ToString();
                }
            }
            catch (Exception ex)
            {

            }
            return isDelay;
        }

        public bool isCurSiteDepDelay(RoadInfo roadSite, Hashtable htNextSiteShouldArriveTime, out string delayTime, Hashtable htDbgBeans)
        {
            delayTime = "";
            bool isDepDelay = false;
            try
            {
                string key = roadSite.jtSiteName + "-" + roadSite.jtNextStopName;
                string keyArrCode = "";
                string keyDesCode = "";
                if (JTTimeEffi.Instance.m_ht_site_map.ContainsKey(roadSite.jtSiteName))
                {
                    keyArrCode = JTTimeEffi.Instance.m_ht_site_map[roadSite.jtSiteName] as string;
                }
                if (JTTimeEffi.Instance.m_ht_site_map.ContainsKey(roadSite.jtNextStopName))
                {
                    keyDesCode = JTTimeEffi.Instance.m_ht_site_map[roadSite.jtNextStopName] as string;
                }
                key = keyArrCode + "-" + keyDesCode;
                if (!JTTimeEffi.Instance.m_ht_effibeans.ContainsKey(key))
                {
                    isDepDelay = noMapBingoJudge(roadSite);
                    return isDepDelay;
                }

                DateTime dtArrival = roadSite.jtArrivalTime;
                TimeSpan tsArrival = dtArrival.TimeOfDay;

                TimeBean timeBean = new bean.TimeBean();
                /*if(!getTimeBeanByTime(key, tsArrival, out timeBean))
                {
                    return isDepDelay;
                }*/
                getTimeBeanByTime(key, tsArrival, out timeBean, htDbgBeans, keyArrCode);
                int addDays = 0;
                TimeSpan tsEnd = new TimeSpan();
                if (timeBean.endDepart.Contains(":"))
                {
                    string[] arr = timeBean.endDepart.Split(':');
                    tsEnd = new TimeSpan(Convert.ToInt32(arr[0]), Convert.ToInt32(arr[1]), 0);
                    if (tsArrival.CompareTo(tsEnd) > 0)
                    {
                        addDays = 1;
                    }
                }




                DateTime dtDep = roadSite.jtDepTime;
                TimeSpan tsDep = dtDep.TimeOfDay;
                int hour = 0;
                int minute = 0;
                utility.Utility.getSepTime(timeBean.endDepart, out hour, out minute);
                TimeSpan tsEndDep = new TimeSpan(hour, minute, 0);

                string strDate = roadSite.jtArrivalTime.ToShortDateString();
                DateTime dtShouldDep = Convert.ToDateTime(strDate) + tsEndDep;
                dtShouldDep = dtShouldDep.AddDays(addDays);

                utility.Utility.getSepTime(timeBean.planArriveNextStie, out hour, out minute);
                TimeSpan tsPlanNext = new TimeSpan(hour, minute, 0);
                DateTime dtPlanNextSite = Convert.ToDateTime(strDate).AddDays(timeBean.transferAddDays + addDays) + tsPlanNext;
                htNextSiteShouldArriveTime[roadSite.jtNextStopName] = dtPlanNextSite;

                if (dtDep > dtShouldDep)
                {
                    TimeSpan tsDiff = dtDep - dtShouldDep;
                    if (tsDiff.TotalMinutes > 3)
                    {
                        isDepDelay = true;
                        TimeSpan tsDelays = dtDep - dtShouldDep;
                        string outputStr = string.Format("{0}天{1}小时", tsDelays.Days, tsDelays.Hours);
                        delayTime = outputStr.ToString();
                    }


                    getTimeBeanByTime(key, tsDep, out timeBean, htDbgBeans, keyDesCode);
                    string[] arr = timeBean.endDepart.Split(':');
                    tsEnd = new TimeSpan(Convert.ToInt32(arr[0]), Convert.ToInt32(arr[1]), 0);
                    if (tsDep.CompareTo(tsEnd) > 0)
                    {
                        addDays = 1;
                    }
                    dtPlanNextSite = Convert.ToDateTime(strDate).AddDays(timeBean.transferAddDays + addDays) + tsPlanNext;
                    htNextSiteShouldArriveTime[roadSite.jtNextStopName] = dtPlanNextSite;

                }

                //TimeSpan tsEnd=

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("isCurSiteDepDelay delay ex:" + ex.ToString());
            }
            return isDepDelay;
        }

        public bool isOverTimeParcel(string barcode, JArray details, RoadInfo roadInfo, Hashtable htdbg)
        {
            bool isOverTime = false;

            for (int i = details.Count - 1; i >= 0; i--)
            {
                JObject jason = (JObject)details[i];

                string status = jason["status"].ToString();
                JToken scanNetworkName = jason["scanNetworkName"];
                JToken scanTypeName = jason["scanTypeName"];
                JToken remark2 = jason["remark2"];
                string scanTime = jason["scanTime"].ToString();
                roadInfo.lastScanStatus = status;

                if (scanTypeName != null && scanTypeName.ToString() == "卸车扫描" && remark2 != null && remark2.ToString().StartsWith("DBG"))
                {
                    DbgBean dbgBean = new DbgBean();
                    htdbg[remark2.ToString()] = dbgBean;
                }
                if (status == "运送中")
                {
                    continue;
                }
                string waybillTrackingContent = jason["waybillTrackingContent"].ToString();
                if (status == "派件中" && scanTypeName.ToString() == "入库扫描" && roadInfo.yizhanRecTime == "" && waybillTrackingContent.Contains("您的快件已存放至"))
                {
                    roadInfo.yizhanRecTime = scanTime;
                }
                if (status == "已签收" && roadInfo.donePackTime == "")
                {
                    roadInfo.donePackTime = scanTime;
                }
            }
            DateTime dtFinish;
            if (roadInfo.yizhanRecTime != "")
            {
                dtFinish = Convert.ToDateTime(roadInfo.yizhanRecTime);
            }
            else if (roadInfo.donePackTime != "")
            {
                dtFinish = Convert.ToDateTime(roadInfo.donePackTime);
            }
            else
            {
                return isOverTime;
            }
            dtFinish = Convert.ToDateTime(dtFinish.ToShortDateString() + " 00:00:00");
            TimeSpan ts = System.DateTime.Now - dtFinish;
            if (Math.Ceiling(ts.TotalDays) > 5)
            {
                isOverTime = true;
            }
            return isOverTime;
        }



        public bool isReallyLateIfUsingTermianlSendTime(ArrayList arListRoadmap, string dispatchSite,string shouldAssignTime)
        {
            bool res = false;
            try
            {
                string terminalSendTime = "";
                string lastPackCenter = "";
                string packageTime = "";
                string lastCenter = "";
                string shouldArrivalTime = "";
                foreach (RoadBean bean in arListRoadmap)
                {
                    RoadBean road = bean;
                    string status = road.status;
                    JToken scanNetworkName = road.scanNetworkName;
                    JToken scanTypeName = road.scanTypeName;
                    string scanTime = road.scanTime;

                    if (scanTypeName != null && scanTypeName.ToString().Contains("发件"))
                    {
                        string nextStopName = road.nextStopName;
                        if(nextStopName== dispatchSite)
                        {
                            terminalSendTime = scanTime;
                            lastCenter = scanNetworkName.ToString();
                        }
                    }
                    if (scanTypeName != null && scanTypeName.ToString().Contains("建包"))
                    {
                        packageTime= scanTime; ;
                        lastPackCenter = scanNetworkName.ToString(); 
                    }
                }
                if (terminalSendTime == "")
                {
                    terminalSendTime = packageTime;
                    lastCenter = lastPackCenter;
                }
                if (terminalSendTime=="")
                {
                    return true;
                }
                if(lastCenter.Contains("A1"))
                {
                    //lastCenter = lastCenter.Replace("A1", "");
                }
                if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(lastCenter) && terminalSendTime != "")
                {
                    Hashtable htCenterSite = LoadBasicHelper.Instance.m_ht_sh_effi[lastCenter] as Hashtable;
                    if (htCenterSite.ContainsKey(dispatchSite))
                    {
                        ArrayList arListEffi = htCenterSite[dispatchSite] as ArrayList;
                        shouldArrivalTime = UtilityHelp.Instance.getMostRecentArrivaTime(Convert.ToDateTime(terminalSendTime), arListEffi);
                        if(Convert.ToDateTime(shouldArrivalTime)>Convert.ToDateTime(shouldAssignTime))
                        {
                            res = true;
                        }
                    }
                    else
                    {
                        res = true;
                    }
                }
                else
                {
                    res = true;
                }

            }
            catch (Exception ex)
            {
                res = true;
            }
            return res;
        }


        public void handleAllGXTime(ArrayList arListRoadmap, Hashtable htTaskTime)
        {
            try
            {
                foreach(RoadBean bean in arListRoadmap)
                {
                    RoadBean road = bean;
                    string status = road.status;
                    JToken scanNetworkName = road.scanNetworkName;
                    JToken scanTypeName = road.scanTypeName;
                    string scanTime = road.scanTime;

                    if (scanTypeName != null && scanTypeName.ToString().Contains("发件")&& (scanNetworkName.ToString().Contains("转运中心")|| scanNetworkName.ToString().Contains("分拨")))
                    {
                        if(htTaskTime.ContainsKey(scanNetworkName.ToString()))
                        {
                            DbgBean dbgBean = htTaskTime[scanNetworkName.ToString()] as DbgBean;
                            if(!utility.Utility.isTimeRight(dbgBean.actualDepartureTime))
                            {
                                dbgBean.actualDepartureTime = Convert.ToDateTime(scanTime);
                            }
                            if(dbgBean.firstTaskNo==""&& road.dkgx!="")
                            {
                                dbgBean.firstTaskNo = road.dkgx;
                            }
                        }
                    }

                }
            }
            catch(Exception ex)
            {

            }
        }


        public bool isContainNextStopSend(ArrayList arListRoadmap,string nextStopName,out bool isContainDbgTask)
        {
            bool isContainFJ = false;
            isContainDbgTask = false;
            try
            {
                foreach (RoadBean bean in arListRoadmap)
                {
                    if(bean.scanTypeName.Contains("发件")&& bean.scanNetworkName== nextStopName)
                    {
                        isContainFJ = true;
                    }
                    if(bean.scanNetworkName== nextStopName&& bean.dkgx!="")
                    {
                        isContainDbgTask = true;
                    }
                }
            }
            catch(Exception x)
            {

            }
            return isContainFJ;
        }

        public void getAllGXTimeByRoadMap(ArrayList arListRoadmap, ArrayList arListGXTask, Hashtable htTaskAndCenter, 
            Hashtable htTaskTime, ArrayList arListCenters,
            Hashtable htRightTimeSites, Hashtable htJSTaskMap,Hashtable htTaskNoDbg,Hashtable htCenterFromList)
        {
            //Hashtable htCenterFromList = new Hashtable();
            try
            {
                Hashtable htCenterSiteTaskMap = new Hashtable();
                ArrayList arListNetWorks = new ArrayList();
                Hashtable htTaskNoMap = new Hashtable();
                htJSTaskMap = new Hashtable();
                foreach (string taskNo in arListGXTask)
                {
                    foreach (RoadBean bean in arListRoadmap)
                    {

                        if (bean.dkgx == taskNo && bean.dkgx.Length > 5 && bean.scanTypeName.Contains("发件"))
                        {
                            if(!htTaskNoDbg.ContainsKey(bean.dkgx))
                            {
                                htTaskNoDbg[bean.dkgx] =new DbgBean();
                            }
                            DbgBean dbgBean = new DbgBean();

                            JToken networkName = bean.scanNetworkName;

                            JToken plannedDepartureTime = (JToken)bean.plannedDepTime;
                            JToken actualDepartureTime = (JToken)bean.actDepTime;

                            JToken nestStopName = (JToken)bean.nextStopName;

                            JToken plannedArrivalTime = (JToken)bean.plannedArrivalTime;

                            

                            if (networkName != null)
                            {
                                if (!arListNetWorks.Contains(networkName.ToString()))
                                {
                                    arListNetWorks.Add(networkName.ToString());
                                }

                                if (!arListCenters.Contains(networkName.ToString()))
                                {
                                    arListCenters.Add(networkName.ToString());
                                }
                                if (bean.nextStopName.Contains("转运") || bean.nextStopName.Contains("分拨"))
                                {
                                    if (!arListCenters.Contains(bean.nextStopName.ToString()))
                                    {
                                        arListCenters.Add(bean.nextStopName.ToString());
                                    }
                                }

                                if (plannedDepartureTime != null && plannedDepartureTime.ToString().Length > 4)
                                {
                                    dbgBean.plannedDepartureTime = Convert.ToDateTime(plannedDepartureTime.ToString());

                                }

                                if (actualDepartureTime != null && actualDepartureTime.ToString().Length > 4)
                                {
                                    dbgBean.actualDepartureTime = Convert.ToDateTime(actualDepartureTime.ToString());
                                }

                                if (!htTaskTime.ContainsKey(networkName.ToString()))
                                {
                                    htTaskTime[networkName.ToString()] = dbgBean;
                                }
                                else
                                {
                                    DbgBean priorDbg = htTaskTime[networkName.ToString()] as DbgBean;
                                    priorDbg.plannedDepartureTime = dbgBean.plannedDepartureTime;
                                    priorDbg.actualDepartureTime = dbgBean.actualDepartureTime;
                                }
                                if(nestStopName!=null&& nestStopName.ToString().Contains("转运中心"))
                                {
                                    DbgBean dbgNextBean = new DbgBean();
                                    dbgNextBean.firstTaskNo = taskNo;
                                    if (plannedArrivalTime != null && plannedArrivalTime.ToString().Length > 4)
                                    {
                                        dbgNextBean.plannedArrivalTime = Convert.ToDateTime(plannedArrivalTime.ToString());
                                    }
                                    if (!htTaskTime.ContainsKey(nestStopName.ToString()))
                                    {
                                        htTaskTime[nestStopName.ToString()] = dbgNextBean;
                                    }


                                }
                                
                                if (bean.nextStopName.ToString().Length > 5 && !htTaskNoMap.ContainsKey(bean.nextStopName.ToString()))
                                {
                                    htTaskNoMap[bean.nextStopName] = taskNo;
                                }




                            }



                        }
                         else if (bean.dkgx== taskNo && bean.dkgx.Length > 5&& bean.scanTypeName.Contains("到件"))
                        {
                            DbgBean dbgBean = new DbgBean();

                            if (!htTaskNoDbg.ContainsKey(bean.dkgx))
                            {
                                htTaskNoDbg[bean.dkgx] = new DbgBean();
                            }

                            JToken networkName = bean.scanNetworkName;

                            JToken plannedDepartureTime = (JToken)bean.plannedDepTime;
                            JToken actualDepartureTime = (JToken)bean.actDepTime; 

                            JToken plannedArrivalTime = (JToken)bean.plannedArrivalTime; 
                            JToken actualArrivalTime = (JToken)bean.actualArrivalTime;

                            if (networkName != null)
                            {
                                if (!htTaskTime.ContainsKey(networkName.ToString()))
                                {
                                    htTaskTime[networkName.ToString()] = dbgBean;
                                }
                                else
                                {
                                    dbgBean = htTaskTime[networkName.ToString()] as DbgBean;
                                }
                                if (!arListNetWorks.Contains(networkName.ToString()))
                                {
                                    arListNetWorks.Add(networkName.ToString());
                                }

                                if (!arListCenters.Contains(networkName.ToString()))
                                {
                                    arListCenters.Add(networkName.ToString());
                                }
                                if(bean.nextStopName.Contains("转运")|| bean.nextStopName.Contains("分拨"))
                                {
                                    if (!arListCenters.Contains(bean.nextStopName.ToString()))
                                    {
                                        arListCenters.Add(bean.nextStopName.ToString());
                                    }
                                    
                                }

                                if (!htCenterSiteTaskMap.ContainsKey(networkName.ToString()))
                                {
                                    ArrayList arListTaskNo = new ArrayList();
                                    arListTaskNo.Add(taskNo);
                                    htCenterSiteTaskMap[networkName.ToString()] = arListTaskNo;
                                }
                                else
                                {
                                    ArrayList arListTaskNo = htCenterSiteTaskMap[networkName.ToString()] as ArrayList;
                                    if(!arListTaskNo.Contains(taskNo))
                                    {
                                        arListTaskNo.Add(taskNo);
                                    }
                                }
                                if(dbgBean.firstTaskNo=="")
                                {
                                    dbgBean.firstTaskNo = taskNo;
                                }
                                else if(dbgBean.secondTaskNo == "")
                                {
                                    dbgBean.secondTaskNo = taskNo;
                                }

                                //todo 此处添加判断任务号是不是同一个转运发出的，同一个转运发出的以最迟的为主，不是同一个转运路线，则按发出的为主
                                if(!UtilityHelp.Instance.isRoadSame(networkName.ToString(), dbgBean.firstTaskNo, taskNo))
                                {
                                   // continue;
                                }    
                                

                                dbgBean = htTaskTime[networkName.ToString()] as DbgBean;
                                dbgBean.DepNetworkName = networkName.ToString();
                                if (plannedDepartureTime != null && plannedDepartureTime.ToString().Length > 4)
                                {
                                    dbgBean.plannedDepartureTime = Convert.ToDateTime(plannedDepartureTime.ToString());
                                   
                                }
                                else
                                {
                                    if (bean.nextStopName.ToString().Length > 5 && !htTaskNoMap.ContainsKey(bean.nextStopName.ToString()))
                                    {
                                        htTaskNoMap[bean.nextStopName] = taskNo;
                                    }
                                }
                                if (actualDepartureTime != null && actualDepartureTime.ToString().Length > 4)
                                {
                                    dbgBean.actualDepartureTime = Convert.ToDateTime(actualDepartureTime.ToString());
                                }
                                if (plannedArrivalTime != null && plannedArrivalTime.ToString().Length > 4 )
                                {
                                    if(!utility.Utility.isTimeRight(dbgBean.plannedArrivalTime))
                                    {
                                        dbgBean.plannedArrivalTime = Convert.ToDateTime(plannedArrivalTime.ToString());
                                    }
                                    else
                                    {
                                        if(dbgBean.plannedArrivalTime < Convert.ToDateTime(plannedArrivalTime.ToString()))
                                        {
                                            dbgBean.plannedArrivalTime = Convert.ToDateTime(plannedArrivalTime.ToString());
                                        }

                                    }
                                    
                                }
                                if (actualArrivalTime != null && actualArrivalTime.ToString().Length > 4 && !utility.Utility.isTimeRight(dbgBean.actualArrivalTime))
                                {
                                    dbgBean.actualArrivalTime = Convert.ToDateTime(actualArrivalTime.ToString());
                                }

                                if (plannedArrivalTime != null && plannedArrivalTime.ToString().Length > 4)
                                {
                                    dbgBean.lastPlannedArrival = Convert.ToDateTime(plannedArrivalTime.ToString());
                                }

                                if (plannedDepartureTime != null && plannedDepartureTime.ToString().Length > 4)
                                {
                                    dbgBean.lastPlannedDepartureTime = Convert.ToDateTime(plannedDepartureTime.ToString());
                                }


                                /*if (plannedArrivalTime != null && plannedArrivalTime.ToString().Length > 4)
                                {
                                    dbgBean.lastPlannedDepartureTime = Convert.ToDateTime(plannedArrivalTime.ToString());
                                }*/
                                if (actualDepartureTime != null && actualDepartureTime.ToString().Length > 4)
                                {
                                    dbgBean.lastActualDepartureTime = Convert.ToDateTime(actualDepartureTime.ToString());
                                }

                                if (htRightTimeSites.ContainsKey(networkName.ToString()))
                                {
                                    DbgBean dbgBeanRightTime = htRightTimeSites[networkName.ToString()] as DbgBean;
                                    if (dbgBeanRightTime.firstTaskNo == taskNo)
                                    {
                                        if (plannedArrivalTime != null && actualArrivalTime != null && plannedArrivalTime.ToString().Length > 4 && actualArrivalTime.ToString().Length > 4 && utility.Utility.isTimeRight(dbgBeanRightTime.firstArrival) && utility.Utility.isTimeRight(Convert.ToDateTime(plannedArrivalTime.ToString())))
                                        {
                                            if (dbgBeanRightTime.firstArrival < Convert.ToDateTime(plannedArrivalTime.ToString()) && Convert.ToDateTime(plannedArrivalTime.ToString()) > Convert.ToDateTime(actualArrivalTime.ToString()))
                                            {
                                                dbgBeanRightTime.firstArrival = Convert.ToDateTime(plannedArrivalTime.ToString());
                                            }
                                        }
                                    }

                                    if (dbgBeanRightTime.secondTaskNo == taskNo)
                                    {
                                        if (plannedArrivalTime != null && actualArrivalTime != null && plannedArrivalTime.ToString().Length > 4 && actualArrivalTime.ToString().Length > 4 &&
                                            utility.Utility.isTimeRight(dbgBeanRightTime.secondArrival)
                                           && utility.Utility.isTimeRight(Convert.ToDateTime(plannedArrivalTime.ToString())))
                                        {
                                            if (dbgBeanRightTime.secondArrival < Convert.ToDateTime(plannedArrivalTime.ToString()) && Convert.ToDateTime(plannedArrivalTime.ToString()) > Convert.ToDateTime(actualArrivalTime.ToString()))
                                            {
                                                dbgBeanRightTime.secondArrival = Convert.ToDateTime(plannedArrivalTime.ToString());
                                            }
                                        }
                                    }

                                }



                            }
                        }


                    }

                    if (!htTaskAndCenter.ContainsKey(taskNo))
                    {
                        htTaskAndCenter[taskNo] = arListNetWorks;
                    }
                }



                Hashtable htTaskTmpMap = new Hashtable();
                if (htTaskNoDbg.Count>0)
                {
                    
                    foreach(DictionaryEntry de in htTaskNoDbg)
                    {
                        string strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/pod/getTaskInfo?taskCode=" + de.Key.ToString();
                        if(StoParams.Instance.isRabbitWin)
                        {
                            strUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/pod/getTaskInfo?taskCode=" + de.Key.ToString();
                        }
                        JObject jObj = new JObject();
                        JArray jarry = new JArray();
                        string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);

                        //string postData = "{\"isAllPod\":1,\"keywordList\":[\"JT5036358713908\",\"JT5036397106300\"],\"trackingTypeEnum\":\"WAYBILL\",\"countryId\":\"1\"}";
                        string response = HttpClient.HttpUtil.Instance.QueryCommon(strUrl, postData, "GET", "trackingExpress");

                        arListNetWorks = new ArrayList();

                        if (response.Contains("data"))
                        {

                            JObject jsonObj = (JObject)JsonConvert.DeserializeObject(response);
                            string resMsg = jsonObj["msg"].ToString();
                            JObject dataObj = (JObject)jsonObj["data"];
                            JToken plannedArrivalTime = dataObj["plannedArrivalTime"];
                            JToken actualArrivalTime = dataObj["actualArrivalTime"];  

                            JToken shipmentName= dataObj["shipmentName"];
                            if (plannedArrivalTime != null && plannedArrivalTime.ToString().Length > 4)
                            {
                                DbgBean dbgTaskBean = (DbgBean)de.Value;

                                if(plannedArrivalTime!=null&& plannedArrivalTime.ToString().Length>1)
                                {
                                    dbgTaskBean.plannedArrivalTime = Convert.ToDateTime(plannedArrivalTime.ToString());

                                }
                                if (actualArrivalTime != null && actualArrivalTime.ToString().Length > 1)
                                {
                                    dbgTaskBean.actualArrivalTime = Convert.ToDateTime(actualArrivalTime.ToString());
                                }

                                if (htTaskTime.ContainsKey(de.Key.ToString()))
                                {
                                   
                                    DbgBean dbgBean = htTaskTime[de.Key.ToString()] as DbgBean;
                                    if (!utility.Utility.isTimeRight(dbgBean.plannedArrivalTime))
                                    {
                                        dbgBean.plannedArrivalTime = Convert.ToDateTime(plannedArrivalTime.ToString());
                                        if(actualArrivalTime!=null && actualArrivalTime.ToString().Length > 5)
                                        {
                                            dbgBean.actualArrivalTime = Convert.ToDateTime(actualArrivalTime.ToString());
                                        }
                                       
                                        dbgBean.shipmentName = shipmentName.ToString();
                                        htTaskTmpMap[de.Key.ToString()] = dbgBean;
                                    }
                                   



                                }
                                else
                                {
                                    DbgBean dbgBean = new DbgBean();
                                    dbgBean.plannedArrivalTime = Convert.ToDateTime(plannedArrivalTime.ToString());
                                    if(actualArrivalTime!=null&& actualArrivalTime.ToString().Length>5)
                                    {
                                        dbgBean.actualArrivalTime = Convert.ToDateTime(actualArrivalTime.ToString());
                                    }
                                   
                                    dbgBean.shipmentName = shipmentName.ToString();
                                    htTaskTime[de.Key.ToString()] = dbgBean;
                                    htTaskTmpMap[de.Key.ToString()] = dbgBean;
                                    if(!StoParams.Instance.isRabbitWin)
                                    {
                                        handleShipment(dbgBean, htCenterFromList, de.Key.ToString());
                                    }
                                    
                                }
                               


                            }
                            


                        }


                     }
                }


                foreach(DictionaryEntry de in htCenterSiteTaskMap)
                {
                    ArrayList arList = (ArrayList)de.Value;
                    ArrayList arListStartCenter = new ArrayList();

                    Hashtable htShipMentDbg = new Hashtable();
                    if(arList.Count>1)
                    {
                        if(htTaskTime.ContainsKey(de.Key))
                        {
                            DbgBean taskDbgBean = htTaskTime[de.Key] as DbgBean;
                            taskDbgBean.isHaveTwoTask = true;
                            string shipment = taskDbgBean.shipmentName;
                            if(shipment.Length>3)
                            {
                                string[] arr = shipment.Split('-');
                                arListStartCenter.Add(arr[0]);
                                htShipMentDbg[arr[0]] = taskDbgBean;
                            }
                        }
                        DbgBean dbgFirstBean = new DbgBean();
                        int curIndex = 0;
                        bool findFirst = false;
                        ArrayList arListTwoDbg = new ArrayList();
                        foreach (string taskNo in arList)
                        {
                            if (htTaskTmpMap.ContainsKey(taskNo))
                            {
                                if(curIndex==0)
                                {
                                    dbgFirstBean = htTaskTmpMap[taskNo] as DbgBean;
                                    findFirst = true;
                                    arListTwoDbg.Add(dbgFirstBean);
                                    continue;
                                }

                            }
                            string strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/pod/getTaskInfo?taskCode=" + taskNo;
                            JObject jObj = new JObject();
                            JArray jarry = new JArray();
                            string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);

                            //string postData = "{\"isAllPod\":1,\"keywordList\":[\"JT5036358713908\",\"JT5036397106300\"],\"trackingTypeEnum\":\"WAYBILL\",\"countryId\":\"1\"}";
                            string response = HttpClient.HttpUtil.Instance.QueryCommon(strUrl, postData, "GET", "trackingExpress");

                            arListNetWorks = new ArrayList();
                            if (response.Contains("data"))
                            {

                                JObject jsonObj = (JObject)JsonConvert.DeserializeObject(response);
                                string resMsg = jsonObj["msg"].ToString();
                                JObject dataObj = (JObject)jsonObj["data"];
                                JToken plannedArrivalTime = dataObj["plannedArrivalTime"];
                                JToken actualArrivalTime = dataObj["actualArrivalTime"];

                                JToken shipmentName = dataObj["shipmentName"];
                                if (plannedArrivalTime != null && plannedArrivalTime.ToString().Length > 4)
                                {
                                    DbgBean dbgBean = new DbgBean();
                                    dbgBean.plannedArrivalTime = Convert.ToDateTime(plannedArrivalTime.ToString());
                                    dbgBean.actualArrivalTime = Convert.ToDateTime(actualArrivalTime.ToString());
                                    dbgBean.shipmentName = shipmentName.ToString();
                                    arListTwoDbg.Add(dbgBean);
                                   

                                    string shipment = dbgBean.shipmentName;
                                    if (shipment.Length > 3)
                                    {
                                        string[] arr = shipment.Split('-');
                                        arListStartCenter.Add(arr[0]);
                                        htShipMentDbg[arr[0]] = dbgBean;
                                    }


                                }



                            }


                            curIndex++;
                        }

                        if(arListStartCenter.Count>1)
                        {
                            string firstCenter = arListStartCenter[0].ToString();
                            string secondCenter = arListStartCenter[1].ToString();
                            if(firstCenter== secondCenter)
                            {
                                if(htTaskTime.ContainsKey(de.Key.ToString()))
                                {
                                    DbgBean curDbg = htTaskTime[de.Key.ToString()] as DbgBean;
                                    if(utility.Utility.isTimeRight(curDbg.lastPlannedArrival))
                                    {
                                        curDbg.plannedArrivalTime = curDbg.lastPlannedArrival;
                                    }
                                    
                                }
                            }
                        }
                        
                    }
                }

                //foreach (RoadBean bean in arListRoadmap)
                //{
                //    if(bean.scanTypeName=="建包"|| bean.scanTypeName == "到件")
                //    {
                //        if(bean.scanNetworkName.Contains("转运"))
                //        {
                //            if()
                //        }
                //    }
                //}


            }
            catch (Exception ex)
            {

            }
        }



        private void handleShipment(DbgBean dbgBean,Hashtable htCenterFromList,string taskNo)
        {
            try
            {
                
                JObject jObj = new JObject();
                JArray jarry = new JArray();


                ArrayList arListNetWorks = new ArrayList();
                bool findRoadMap = false;

                string strUrl = "https://jmsgw.jtexpress.com.cn/transportation/tmsVehicleLine/listByLineName";
                jObj = new JObject();
                jObj["name"] = dbgBean.shipmentName.ToString();
                jObj["countryId"] = "1";
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);

                string resMsg = HttpClient.HttpUtil.Instance.PostCommon(strUrl, postData, "lineMainNew|transportPlatformIndex");
                JObject jsonObj = (JObject)JsonConvert.DeserializeObject(resMsg);
                JArray dataObjArr = (JArray)jsonObj["data"];
                for (int i = 0; i < dataObjArr.Count; i++)
                {
                    JObject jObjData = (JObject)dataObjArr[i];
                    JToken name = jObjData["name"];
                    JToken endName = jObjData["endName"];

                    JToken planArrivalTime = jObjData["plannedArrivalTime"];
                    JToken startName= jObjData["startName"];
                    //if(!dbgBean.fromCenter.Contains(startName.ToString()))
                    {
                        dbgBean.fromCenter.Add(startName.ToString());
                    }
                    if(!htCenterFromList.ContainsKey(startName.ToString()))
                    {
                        htCenterFromList[startName.ToString()] = new ArrayList();
                    }
                    ArrayList arListTaskNo = htCenterFromList[startName.ToString()] as ArrayList;
                    if(!arListTaskNo.Contains(taskNo)&& taskNo.Length>3)
                    {
                        arListTaskNo.Add(taskNo);
                    }

                }







            }
            catch (Exception ex)
            {

            }
        }

        public void getAllGXTime(ArrayList arListGXTask, Hashtable htTaskAndCenter, Hashtable htTaskTime, ArrayList arListCenters, Hashtable htRightTimeSites)
        {
            try
            {
                foreach (string taskNo in arListGXTask)
                {
                    string strUrl = "https://jmsgw.jtexpress.com.cn/sqsthird/thirdService/ops/shipment/getStopList?shipmentNo=" + taskNo;

                    JObject jObj = new JObject();
                    JArray jarry = new JArray();
                    string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);

                    //string postData = "{\"isAllPod\":1,\"keywordList\":[\"JT5036358713908\",\"JT5036397106300\"],\"trackingTypeEnum\":\"WAYBILL\",\"countryId\":\"1\"}";
                    string response = HttpClient.HttpUtil.Instance.QueryCommon(strUrl, postData, "GET", "arbitrationApply");

                    ArrayList arListNetWorks = new ArrayList();
                    if (response.Contains("data"))
                    {

                        JObject jsonObj = (JObject)JsonConvert.DeserializeObject(response);
                        string resMsg = jsonObj["msg"].ToString();
                        JArray dataArr = (JArray)jsonObj["data"];
                        if (dataArr != null)
                        {
                            for (int i = 0; i < dataArr.Count; i++)
                            {
                                DbgBean dbgBean = new DbgBean();
                                JObject jsonDetails = (JObject)dataArr[i];
                                JToken networkName = (JToken)jsonDetails["networkName"];

                                JToken plannedDepartureTime = (JToken)jsonDetails["plannedDepartureTime"];
                                JToken actualDepartureTime = (JToken)jsonDetails["actualDepartureTime"];

                                JToken plannedArrivalTime = (JToken)jsonDetails["plannedArrivalTime"];
                                JToken actualArrivalTime = (JToken)jsonDetails["actualArrivalTime"];


                                if (networkName != null)
                                {
                                    if (!arListNetWorks.Contains(networkName.ToString()))
                                    {
                                        arListNetWorks.Add(networkName.ToString());
                                    }

                                    if (!arListCenters.Contains(networkName.ToString()))
                                    {
                                        arListCenters.Add(networkName.ToString());
                                    }

                                    if (!htTaskTime.ContainsKey(networkName.ToString()))
                                    {
                                        htTaskTime[networkName.ToString()] = dbgBean;
                                    }

                                    dbgBean = htTaskTime[networkName.ToString()] as DbgBean;
                                    dbgBean.DepNetworkName = networkName.ToString();
                                    if (plannedDepartureTime != null && plannedDepartureTime.ToString().Length > 4)
                                    {
                                        dbgBean.plannedDepartureTime = Convert.ToDateTime(plannedDepartureTime.ToString());
                                    }
                                    if (actualDepartureTime != null && actualDepartureTime.ToString().Length > 4)
                                    {
                                        dbgBean.actualDepartureTime = Convert.ToDateTime(actualDepartureTime.ToString());
                                    }
                                    if (plannedArrivalTime != null && plannedArrivalTime.ToString().Length > 4 && !utility.Utility.isTimeRight(dbgBean.plannedArrivalTime))
                                    {
                                        dbgBean.plannedArrivalTime = Convert.ToDateTime(plannedArrivalTime.ToString());
                                    }
                                    if (actualArrivalTime != null && actualArrivalTime.ToString().Length > 4 && !utility.Utility.isTimeRight(dbgBean.actualArrivalTime))
                                    {
                                        dbgBean.actualArrivalTime = Convert.ToDateTime(actualArrivalTime.ToString());
                                    }

                                    if (plannedArrivalTime != null && plannedArrivalTime.ToString().Length > 4)
                                    {
                                        dbgBean.lastPlannedArrival = Convert.ToDateTime(plannedArrivalTime.ToString());
                                    }

                                    if (plannedDepartureTime != null && plannedDepartureTime.ToString().Length > 4)
                                    {
                                        dbgBean.lastPlannedDepartureTime = Convert.ToDateTime(plannedDepartureTime.ToString());
                                    }


                                    if (plannedArrivalTime != null && plannedArrivalTime.ToString().Length > 4)
                                    {
                                        dbgBean.lastPlannedDepartureTime = Convert.ToDateTime(plannedArrivalTime.ToString());
                                    }
                                    if (actualDepartureTime != null && actualDepartureTime.ToString().Length > 4)
                                    {
                                        dbgBean.lastActualDepartureTime = Convert.ToDateTime(actualDepartureTime.ToString());
                                    }

                                    if (htRightTimeSites.ContainsKey(networkName.ToString()))
                                    {
                                        DbgBean dbgBeanRightTime = htRightTimeSites[networkName.ToString()] as DbgBean;
                                        if (dbgBeanRightTime.firstTaskNo == taskNo)
                                        {
                                            if (plannedArrivalTime != null && actualArrivalTime != null && plannedArrivalTime.ToString().Length > 4 && actualArrivalTime.ToString().Length > 4 && utility.Utility.isTimeRight(dbgBeanRightTime.firstArrival) && utility.Utility.isTimeRight(Convert.ToDateTime(plannedArrivalTime.ToString())))
                                            {
                                                if (dbgBeanRightTime.firstArrival < Convert.ToDateTime(plannedArrivalTime.ToString()) && Convert.ToDateTime(plannedArrivalTime.ToString()) > Convert.ToDateTime(actualArrivalTime.ToString()))
                                                {
                                                    dbgBeanRightTime.firstArrival = Convert.ToDateTime(plannedArrivalTime.ToString());
                                                }
                                            }
                                        }

                                        if (dbgBeanRightTime.secondTaskNo == taskNo)
                                        {
                                            if (plannedArrivalTime != null && actualArrivalTime != null && plannedArrivalTime.ToString().Length > 4 && actualArrivalTime.ToString().Length > 4 &&
                                                utility.Utility.isTimeRight(dbgBeanRightTime.secondArrival)
                                               && utility.Utility.isTimeRight(Convert.ToDateTime(plannedArrivalTime.ToString())))
                                            {
                                                if (dbgBeanRightTime.secondArrival < Convert.ToDateTime(plannedArrivalTime.ToString()) && Convert.ToDateTime(plannedArrivalTime.ToString()) > Convert.ToDateTime(actualArrivalTime.ToString()))
                                                {
                                                    dbgBeanRightTime.secondArrival = Convert.ToDateTime(plannedArrivalTime.ToString());
                                                }
                                            }
                                        }

                                    }


                                    /*if (plannedDepartureTime != null && plannedDepartureTime.ToString().Length > 4 )
                                    {
                                        dbgBean.plannedDepartureTime = Convert.ToDateTime(plannedDepartureTime.ToString());
                                    }
                                    if (actualDepartureTime != null && actualDepartureTime.ToString().Length > 4 )
                                    {
                                        dbgBean.actualDepartureTime = Convert.ToDateTime(actualDepartureTime.ToString());
                                    }
                                    if (plannedArrivalTime != null && plannedArrivalTime.ToString().Length > 4 )
                                    {
                                        dbgBean.plannedArrivalTime = Convert.ToDateTime(plannedArrivalTime.ToString());
                                    }
                                    if (actualArrivalTime != null && actualArrivalTime.ToString().Length > 4 )
                                    {
                                        dbgBean.actualArrivalTime = Convert.ToDateTime(actualArrivalTime.ToString());
                                    }*/

                                }


                            }

                        }

                    }
                    if (!htTaskAndCenter.ContainsKey(taskNo))
                    {
                        htTaskAndCenter[taskNo] = arListNetWorks;
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }

        public bool isDeferNetwork(string strCurBarcode, out string msg, 
            string strInterCeptSiteCode, string siteName,ArrayList arListDelayDays)
        {
            msg = "";
            bool res = false;
            try
            {
                string strUrl = "https://jmsgw.jtexpress.com.cn/servicequality/problemPiece/getPageByName?current=1&size=10&queryLevel=3&name=" + siteName;
                if(StoParams.Instance.isRabbitWin)
                {
                    strUrl = "https://wdgw.jtexpress.com.cn/servicequality/problemPiece/getPageByName?current=1&size=10&queryLevel=3&name=" + siteName;
                }
                JObject jObj = new JObject();
                JArray jarry = new JArray();

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string resMsg = HttpClient.HttpUtil.Instance.QueryCommon(strUrl, postData, "GET", "batchProblem");
                if (!resMsg.Contains("请求成功"))
                {
                    return false;
                }
                JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                JObject jsonObjData = (JObject)jsonObjRes["data"];
                JArray records = (JArray)jsonObjData["records"];
                if (records.Count == 0)
                {
                    msg = "网点：" + siteName + " 不存在,跳过催件环节";
                    return false;
                }
                string signStieCode = "";
                int receiveNetworkId = 0;
                for (int i = 0; i < records.Count; i++)
                {
                   
                    JObject json = (JObject)records[i];
                    JToken code = json["code"];
                    JToken name = json["name"];
                    JToken id = json["id"];
                    if (code != null)
                    {
                        if (name.ToString() == siteName)
                        {
                            signStieCode = code.ToString();
                            if (id != null)
                            {
                                receiveNetworkId = Convert.ToInt32(id);
                            }
                            break;
                        }
                    }
                }
                if (signStieCode == "" || receiveNetworkId == 0)
                {
                    return false;
                }
                strUrl = "https://jmsgw.jtexpress.com.cn/servicequality/abnormalEvent/selectListByDeferNetwork";
                if(StoParams.Instance.isRabbitWin)
                {
                    strUrl = "https://wdgw.jtexpress.com.cn/servicequality/abnormalEvent/selectListByDeferNetwork";
                }
                string routerName = "arbitrationApply";
                jObj = new JObject();
                jObj["countryId"] = "1";
                jObj["deferNetworkCode"] = signStieCode;                
                jObj["waybillNo"] = strCurBarcode;
                postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);

                resMsg = HttpClient.HttpUtil.Instance.PostCommon(strUrl, postData, routerName);
                if (!resMsg.Contains("请求成功"))
                {
                    jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                    JToken msgToke = jsonObjRes["msg"];
                    return false;
                }
                jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                records = (JArray)jsonObjRes["data"];
                for (int i = 0; i < records.Count; i++)
                {
                    res = true;
                    JObject jobj = (JObject)records[i];
                    string happenTime = jobj["happenTime"].ToString();
                    string deferEndTime = jobj["deferEndTime"].ToString();
                    int delayDays = Convert.ToInt32(jobj["deferDay"].ToString());
                    DelaySiteBean delayBean = new DelaySiteBean();
                    delayBean.starTime = Convert.ToDateTime(happenTime);
                    delayBean.endTime = Convert.ToDateTime(deferEndTime);
                    delayBean.delayDays = delayDays;
                    arListDelayDays.Add(delayBean);
                }



            }
            catch (Exception ex)
            {

            }



            return res;
        }


        public bool isSignSiteRight(string dispatchSite,ArrayList arListRoadMap)
        {
            bool res = true;
            try
            {
                bool isReturnParcel = false;
                string priorUsefulNetWork = "";
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean road = (RoadBean)arListRoadMap[i];
                    string status = road.status;
                    JToken scanNetworkName = road.scanNetworkName;
                    JToken scanTypeName = road.scanTypeName;

                    if(road.scanNetworkName!="")
                    {
                        priorUsefulNetWork = road.scanNetworkName;
                    }
                    if(scanTypeName.ToString().Contains("退件"))
                    {
                        isReturnParcel = true;
                    }
                    if (scanTypeName != null && road.waybillTrackingContent.Contains("签收"))
                    {
                        if(dispatchSite!= priorUsefulNetWork && !isReturnParcel&& priorUsefulNetWork != "")
                        {
                            res = false;
                            return res;
                        }
                        
                    }
                    if(!isReturnParcel)
                    {
                        if(scanNetworkName.ToString().Contains("分拨")|| scanNetworkName.ToString().Contains("集散")
                            || scanNetworkName.ToString().Contains("转运中心"))
                        {
                            if(scanTypeName.ToString().Contains("发件"))
                            {
                                if(road.nextStopName.Contains("网点")&& road.nextStopName!= dispatchSite)
                                {
                                    //res = false;
                                    //return res;
                                }
                            }
                        }

                        if (scanNetworkName.ToString().Contains("网点"))
                        {
                            if (road.nextStopName != dispatchSite&& road.waybillTrackingContent.Contains("抬头错"))
                            {
                                //res = false;
                                //return res;
                            }
                        }
                    }
                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }

        public bool isEffiLate(string barcode, ArrayList details, out string dispatchSite, out string dispatchSiteArrival, 
            out string terminalDepTime, out string assignTime,out string shouldAssignTime,out string sendToDesSite,
            out string orderDispatchSite,Hashtable htJS)
        {
            bool res = false;
            dispatchSite = "";
            sendToDesSite = "";
            dispatchSiteArrival = "";
            terminalDepTime = "";
            shouldAssignTime = "";
            string lastDepTime = "";
            assignTime = "";
            orderDispatchSite = "";
            try
            {
                string strLanshouSite = "";
                string depTime = "";
                string assignSite = "";

                string destCity = "";
                string sourceCity = "";


                string strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/order/getOrderDetail";
                if(StoParams.Instance.isRabbitWin)
                {
                    strUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/order/getOrderDetail";
                }

                JObject jObj = new JObject();
                jObj["waybillNo"] = barcode;
                jObj["countryId"] = "1";




                JArray jarry = new JArray();

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);

                //string postData = "{\"isAllPod\":1,\"keywordList\":[\"JT5036358713908\",\"JT5036397106300\"],\"trackingTypeEnum\":\"WAYBILL\",\"countryId\":\"1\"}";
                string response = HttpClient.HttpUtil.Instance.PostCommon(strUrl, postData, "trackingExpress");

                if (response.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(response);
                    string resMsg = jsonObj["msg"].ToString();
                    JObject dataObj = (JObject)jsonObj["data"];
                    JObject jsonDetails = (JObject)dataObj["details"];
                    if (jsonDetails != null)
                    {
                        JToken senderCityName = (JToken)jsonDetails["senderCityName"];
                        JToken receiverCityName = (JToken)jsonDetails["receiverCityName"];
                        JToken deliveryTime = (JToken)jsonDetails["pickTime"];
                        JToken pickNetworkName = (JToken)jsonDetails["pickNetworkName"];
                        JToken dispatchNetworkName = (JToken)jsonDetails["dispatchNetworkName"];
                        if (pickNetworkName != null)
                        {
                            strLanshouSite = pickNetworkName.ToString();
                        }
                        if (deliveryTime != null)
                        {
                            depTime = deliveryTime.ToString();
                        }
                        if (senderCityName != null)
                        {
                            sourceCity = senderCityName.ToString();
                        }
                        if (receiverCityName != null)
                        {
                            destCity = receiverCityName.ToString();
                        }
                        if (dispatchNetworkName != null)
                        {
                            dispatchSite = dispatchNetworkName.ToString();
                            orderDispatchSite = dispatchNetworkName.ToString();
                        }

                    }

                }
                
                for (int i = 0; i < details.Count; i++)
                {
                    RoadBean road = (RoadBean)details[i];
                    string status = road.status;
                    JToken scanNetworkName = road.scanNetworkName;
                    JToken scanTypeName = road.scanTypeName;
                    if(scanTypeName.ToString().Contains("发件"))
                    {
                        JToken nextStopName = road.nextStopName;
                        if(nextStopName.ToString().Contains("集散")&& (scanNetworkName.ToString().Contains("转运")|| scanNetworkName.ToString().Contains("分拨")))
                        {
                            htJS[nextStopName.ToString()] = scanNetworkName.ToString();
                        }
                    }
                    if(scanTypeName != null&& scanTypeName.ToString().Contains("快件签收"))
                    {
                        if(i== (details.Count-1))
                        {
                            if(dispatchSite!= road.scanNetworkName)
                            {
                                dispatchSite = road.scanNetworkName;
                            }
                        }
                    }
                }
                string firstCenter = "";
                for (int i = 0; i < details.Count; i++)
                {
                    RoadBean road = (RoadBean)details[i];
                    string status = road.status;
                    JToken scanNetworkName = road.scanNetworkName;
                    JToken scanTypeName = road.scanTypeName;
                    string scanTime = road.scanTime;

                    if (scanTypeName != null && scanTypeName.ToString().Contains("揽收") && strLanshouSite == "")
                    {
                        if (scanNetworkName != null)
                        {
                            strLanshouSite = scanNetworkName.ToString();
                        }
                        if (scanTime != null && depTime != "")
                        {
                            //depTime = scanTime.ToString();
                        }
                    }

                    if (scanNetworkName.ToString() == StoParams.Instance.register_site && scanTypeName.Contains("发件") && depTime == "")
                    {
                        firstCenter = scanNetworkName.ToString();
                        depTime = scanTime;
                    }

                    if (scanTypeName != null && scanTypeName.ToString().Contains("卸车到件") && strLanshouSite == "")
                    {
                        if (scanNetworkName != null)
                        {
                            strLanshouSite = scanNetworkName.ToString();
                        }

                    }

                    if (scanTypeName != null && scanTypeName.ToString().Contains("到件") && scanNetworkName.ToString() != StoParams.Instance.register_site && scanNetworkName.ToString().Contains("网点"))
                    {
                        if (dispatchSite == scanNetworkName.ToString() || dispatchSite == "")
                        {
                            if (scanNetworkName != null)
                            {
                                assignSite = scanNetworkName.ToString();
                            }
                            if (scanTime != null && dispatchSiteArrival == "")
                            {
                                dispatchSiteArrival = scanTime;
                            }
                        }


                    }

                    if (scanTypeName != null && scanTypeName.ToString().Contains("出仓扫描") && scanNetworkName.ToString() != StoParams.Instance.register_site && scanNetworkName.ToString().Contains("网点") && status.Contains("派件"))
                    {
                        if (dispatchSite == scanNetworkName.ToString() || dispatchSite == "")
                        {
                            if (scanTime != null)
                            {
                                assignTime = scanTime.ToString();
                            }
                        }

                    }

                    if (scanTypeName != null && scanTypeName.ToString().Contains("发件"))
                    {
                        if (scanTime != null)
                        {
                            string nextName = road.nextStopName;
                            /*if(nextName.Contains("BEST"))
                            {
                                return false;
                            }*/
                        }
                    }


                    if (scanTypeName != null && scanTypeName.ToString().Contains("发件") && scanNetworkName.ToString() != StoParams.Instance.register_site && !scanNetworkName.ToString().Contains("网点"))
                    {
                        if (scanTime != null)
                        {
                            terminalDepTime = scanTime.ToString();
                            lastDepTime = scanTime.ToString();
                        }
                    }

                    if (scanTypeName != null && scanTypeName.ToString().Contains("发件") && road.nextStopName==dispatchSite)
                    {
                        if (scanTime != null)
                        {
                            sendToDesSite= scanTime.ToString();
                            //terminalDepTime = scanTime.ToString();
                            //lastDepTime = scanTime.ToString();
                        }
                    }

                }

                /*if (!MemberInfo.Instance.htSiteCityMap.ContainsKey(strLanshouSite))
                {
                    return res;
                }*/
                //else
                {
                    if (destCity == "" && assignSite != "")
                    {
                        destCity = MemberInfo.Instance.getDestCity(assignSite);
                    }
                    if (destCity != "")
                    {
                        if (MemberInfo.Instance.htDesCityEffi.ContainsKey(destCity))
                        {
                            int effiDays = Convert.ToInt32(MemberInfo.Instance.htDesCityEffi[destCity].ToString());
                            if(LoadBasicHelper.Instance.isEffiCheck)
                            {
                                effiDays = effiDays - 1;

                            }
                            string depDate = Convert.ToDateTime(depTime).ToShortDateString();
                            string shouldAssign = Convert.ToDateTime(depDate).AddDays(effiDays).ToString();
                            if (assignTime == "")
                            {
                                //res = true;
                            }
                            else
                            {
                                if (Convert.ToDateTime(assignTime) > Convert.ToDateTime(shouldAssign))
                                {
                                    shouldAssignTime = shouldAssign;
                                    //res = true;
                                }
                            }
                        }
                        else
                        {
                            int a = 0;
                        }
                    }
                }

            }
            catch (Exception ex)
            {

            }
            if (dispatchSiteArrival == "")
            {
                dispatchSiteArrival = lastDepTime;
            }
            return res;

        }



        public bool isSortWrongDelay(string barcode, JArray details, RoadInfo roadInfo, out int res, out bool isReturnParcel, Hashtable htSiteDbgs)
        {
            isReturnParcel = false;
            bool isSortWrong = false;
            res = 0;
            try
            {
                ArrayList arListDetails = new ArrayList();
                int count = 0;
                string siteName = "";
                string tmpSite = "";
                string lastSite = "";
                bool isPacelInYizhan = false;
                Hashtable htCurSiteShouldArrival = new Hashtable();
                Hashtable htCurSiteBean = new Hashtable();
                ArrayList arListRoadSites = new ArrayList();
                RoadInfo priorRoadInfo = new RoadInfo();

                Hashtable htArrivalSite = new Hashtable();
                Hashtable htArrivalTimeSite = new Hashtable();
                ArrayList arListAllDepRoadSite = new ArrayList();
                ArrayList arListAllRoadSites = new ArrayList();
                string assignSite = "";
                for (int i = details.Count - 1; i >= 0; i--)
                {
                    JObject jason = (JObject)details[i];
                    arListDetails.Add(jason);
                    count++;
                    string status = jason["status"].ToString();
                    JToken scanNetworkName = jason["scanNetworkName"];
                    JToken scanTypeName = jason["scanTypeName"];
                    string scanTime = jason["scanTime"].ToString();
                    roadInfo.lastScanStatus = status;

                    RoadInfo curRoad = new RoadInfo();
                    curRoad.lastScanStatus = status;

                    curRoad.jtScanTime = Convert.ToDateTime(scanTime);
                    if (!utility.Utility.IsNullOrEmpty(scanNetworkName))
                    {
                        curRoad.jtSiteName = scanNetworkName.ToString();
                    }
                    arListAllRoadSites.Add(curRoad);
                    if (!utility.Utility.IsNullOrEmpty(status) && status.ToString() == "派件中")
                    {
                        assignSite = scanNetworkName.ToString();
                    }
                    if (!utility.Utility.IsNullOrEmpty(scanNetworkName) && !utility.Utility.IsNullOrEmpty(scanTypeName))
                    {
                        curRoad.jtScanType = scanTypeName.ToString();
                    }

                    if (!utility.Utility.IsNullOrEmpty(scanNetworkName) && !utility.Utility.IsNullOrEmpty(scanTypeName)
                        && (scanTypeName.ToString() == "发件扫描"|| scanTypeName.ToString() == "装车发件"))
                    {
                        curRoad.jtSiteName = scanNetworkName.ToString();
                        JToken nextStopName = jason["nextStopName"];
                        if (!utility.Utility.IsNullOrEmpty(nextStopName))
                        {
                            curRoad.jtNextStopName = nextStopName.ToString();
                        }
                        curRoad.jtDepTime = Convert.ToDateTime(scanTime);
                        arListAllDepRoadSite.Add(curRoad);
                    }

                    if (scanTypeName != null && scanTypeName.ToString() == "问题件扫描")
                    {
                        JToken waybillTrackingContent = jason["waybillTrackingContent"];
                        if (waybillTrackingContent != null && waybillTrackingContent.ToString().Contains("错分"))
                        {
                            isSortWrong = true;
                            DateTime dtPrior = priorRoadInfo.jtDepTime;
                            TimeSpan ts = Convert.ToDateTime(scanTime) - dtPrior;
                            string outputStr = string.Format("{0}天{1}小时", ts.Days, ts.Hours);
                            roadInfo.strErrorMsg = "错分件 " + priorRoadInfo.jtSiteName + " 错发" + scanNetworkName;
                            roadInfo.jtDelaySite = priorRoadInfo.jtSiteName;
                            roadInfo.jtDelayTime = outputStr;
                            //return isSortWrong;
                        }
                        //if()
                    }

                    if (scanTypeName != null && scanTypeName.ToString() == "退件登记")
                    {
                        JToken waybillTrackingContent = jason["waybillTrackingContent"];
                        if (!utility.Utility.IsNullOrEmpty(waybillTrackingContent) && waybillTrackingContent != null && waybillTrackingContent.ToString().Contains("退回件登记"))
                        {
                            isReturnParcel = true;
                            return isSortWrong;
                        }
                        //if()
                    }



                    if (scanTypeName != null && (scanTypeName.ToString() == "发件扫描"|| scanTypeName.ToString() == "装车发件"))
                    {
                        curRoad.jtDepTime = Convert.ToDateTime(scanTime);
                        JToken nextStopName = jason["nextStopName"];
                        if (nextStopName != null)
                        {

                            tmpSite = nextStopName.ToString();
                            curRoad.jtNextStopName = tmpSite;
                            string strKey = scanNetworkName.ToString() + "-" + curRoad.jtNextStopName;
                            string revertKey = curRoad.jtNextStopName + "-" + scanNetworkName.ToString();
                            htCurSiteBean[strKey] = Convert.ToDateTime(scanTime);
                            if (htCurSiteBean.ContainsKey(revertKey))
                            {
                                isSortWrong = true;
                                DateTime dtPrior = Convert.ToDateTime(htCurSiteBean[revertKey].ToString());
                                TimeSpan ts = Convert.ToDateTime(scanTime) - dtPrior;
                                string outputStr = string.Format("{0}天{1}小时", ts.Days, ts.Hours);
                                roadInfo.strErrorMsg = "错分件 " + curRoad.jtNextStopName + " 错发" + scanNetworkName;
                                roadInfo.jtDelaySite = curRoad.jtNextStopName;
                                roadInfo.jtDelayTime = outputStr;
                                return isSortWrong;

                            }
                            priorRoadInfo.jtDepTime = Convert.ToDateTime(scanTime);
                            priorRoadInfo.jtSiteName = scanNetworkName.ToString();
                        }
                    }


                    if (!utility.Utility.IsNullOrEmpty(scanTypeName) && scanTypeName != null && scanTypeName.ToString() == "卸车扫描")
                    {
                        curRoad.jtArrivalTime = Convert.ToDateTime(scanTime);

                        if (!htArrivalSite.ContainsKey(scanNetworkName))
                        {
                            htArrivalSite[scanNetworkName] = i;
                            htArrivalTimeSite[scanNetworkName] = scanTime;
                        }
                        else
                        {
                            int priorIndex = Convert.ToInt32(htArrivalSite[scanNetworkName]);
                            if (Math.Abs(priorIndex - i) > 2)
                            {
                                string errorSendSite = "";
                                if (utility.Utility.isSorWrongThisSite(priorIndex, i, details, scanNetworkName.ToString(), out errorSendSite))
                                {
                                    isSortWrong = true;
                                    DateTime dtPrior = Convert.ToDateTime(htArrivalTimeSite[scanNetworkName].ToString());
                                    TimeSpan ts = Convert.ToDateTime(scanTime) - dtPrior;
                                    string outputStr = string.Format("{0}天{1}小时", ts.Days, ts.Hours);
                                    roadInfo.strErrorMsg = "错分件 " + scanNetworkName + " 错发" + errorSendSite;
                                    roadInfo.jtDelaySite = scanNetworkName.ToString();
                                    roadInfo.jtDelayTime = outputStr;
                                    return isSortWrong;
                                }

                            }

                        }
                    }
                }
                Hashtable htDepRoads = new Hashtable();
                DateTime dtErrorScanBegin;
                foreach (RoadInfo curRoad in arListAllDepRoadSite)
                {
                    if (!htDepRoads.ContainsKey(curRoad.jtSiteName))
                    {
                        htDepRoads[curRoad.jtSiteName] = curRoad;
                    }
                    if (htDepRoads.ContainsKey(curRoad.jtNextStopName))
                    {
                        DateTime dtCur = curRoad.jtDepTime;
                        RoadInfo prior = (RoadInfo)htDepRoads[curRoad.jtNextStopName];
                        DateTime dtPrior = prior.jtScanTime;
                        dtErrorScanBegin = dtPrior;
                        TimeSpan ts = dtCur - dtPrior;
                        if (ts.TotalHours > 8)
                        {
                            isSortWrong = true;
                            roadInfo.jtDelaySite = curRoad.jtNextStopName;
                            TimeSpan tsDelay = utility.Utility.getDelayTime(arListAllRoadSites, curRoad.jtNextStopName, curRoad.jtSiteName, dtErrorScanBegin);
                            string outputStr = string.Format("{0}天{1}小时", tsDelay.Days, tsDelay.Hours);
                            roadInfo.strErrorMsg = "错分件 " + curRoad.jtNextStopName + " 错发" + curRoad.jtSiteName;
                            roadInfo.jtDelayTime = outputStr;
                            return isSortWrong;
                        }
                    }
                }
                string outStrMsg = "";
                isSortWrong = isSortToDifferetSite(arListAllRoadSites, assignSite, out outStrMsg, htSiteDbgs, roadInfo);
            }
            catch (Exception ex)
            {

            }
            return isSortWrong;
        }


        public bool isSortToDifferetSite(ArrayList arListRoads, string lastSite, out string delayTime, Hashtable htDbgBeans, RoadInfo globalRoad)
        {
            delayTime = "";
            bool isDelay = false;
            try
            {
                bool bingo = false;
                ArrayList arListDifferntSites = new ArrayList();
                bool firstNearSiteBingo = false;
                bool nextNearSiteBingo = false;
                DateTime dtLastSiteArrivaTime = System.DateTime.Now;
                string key = "";
                string keyArrCode = "";
                string keyDesCode = "";
                for (int i = arListRoads.Count - 1; i >= 0; i--)
                {
                    RoadInfo roadInfo = (RoadInfo)arListRoads[i];
                    if (lastSite == roadInfo.jtSiteName)
                    {
                        bingo = true;
                        if (roadInfo.jtScanType == "卸车扫描" || roadInfo.jtScanType == "到件扫描" || roadInfo.jtScanType == "卸车到件")
                        {
                            dtLastSiteArrivaTime = roadInfo.jtScanTime;
                        }
                    }
                    else
                    {
                        if (bingo)
                        {
                            if (!arListDifferntSites.Contains(roadInfo.jtSiteName))
                            {
                                arListDifferntSites.Add(roadInfo.jtSiteName);
                            }

                            string curSite = roadInfo.jtSiteName;

                            if (JTTimeEffi.Instance.m_ht_site_map.ContainsKey(roadInfo.jtSiteName))
                            {
                                keyArrCode = JTTimeEffi.Instance.m_ht_site_map[roadInfo.jtSiteName] as string;
                            }
                            if (JTTimeEffi.Instance.m_ht_site_map.ContainsKey(lastSite))
                            {
                                keyDesCode = JTTimeEffi.Instance.m_ht_site_map[lastSite] as string;
                            }
                            key = keyArrCode + "-" + keyDesCode;
                            if (arListDifferntSites.Count == 1)
                            {
                                if (JTTimeEffi.Instance.m_ht_effibeans.ContainsKey(key))
                                {
                                    firstNearSiteBingo = true;
                                    return isDelay;
                                }
                            }
                            else if (arListDifferntSites.Count >= 2)
                            {
                                if (JTTimeEffi.Instance.m_ht_effibeans.ContainsKey(key))
                                {
                                    nextNearSiteBingo = true;
                                    break;
                                }

                            }

                        }
                    }
                }


                if (nextNearSiteBingo && !firstNearSiteBingo)
                {
                    isDelay = true;
                    string sortToWrongSite = arListDifferntSites[0].ToString();
                    string sortWrongCenter = arListDifferntSites[1].ToString();
                    DateTime dtArrivalCenter = System.DateTime.Now;
                    foreach (RoadInfo roadInfo in arListRoads)
                    {
                        if (roadInfo.jtSiteName == arListDifferntSites[1].ToString() && roadInfo.jtScanType == "卸车扫描")
                        {
                            dtArrivalCenter = roadInfo.jtScanTime;
                            break;
                        }
                    }


                    TimeBean timeBean = new bean.TimeBean();
                    TimeSpan tsArrival = dtArrivalCenter.TimeOfDay;
                    getTimeBeanByTime(key, tsArrival, out timeBean, htDbgBeans, keyArrCode);
                    int addDays = 0;
                    TimeSpan tsEnd = new TimeSpan();
                    if (timeBean.endDepart.Contains(":"))
                    {
                        string[] arr = timeBean.endDepart.Split(':');
                        tsEnd = new TimeSpan(Convert.ToInt32(arr[0]), Convert.ToInt32(arr[1]), 0);
                        if (tsArrival.CompareTo(tsEnd) > 0)
                        {
                            addDays = 1;
                        }
                    }

                    //DateTime dtDep = roadSite.jtDepTime;
                    //TimeSpan tsDep = dtDep.TimeOfDay;
                    int hour = 0;
                    int minute = 0;
                    /*utility.Utility.getSepTime(timeBean.endDepart, out hour, out minute);
                    TimeSpan tsEndDep = new TimeSpan(hour, minute, 0);

                    string strDate = dtArrivalCenter.ToShortDateString();
                    DateTime dtShouldDep = Convert.ToDateTime(strDate) + tsEndDep;
                    dtShouldDep = dtShouldDep.AddDays(addDays);*/
                    string strDate = dtArrivalCenter.ToShortDateString();
                    utility.Utility.getSepTime(timeBean.planArriveNextStie, out hour, out minute);
                    TimeSpan tsPlanNext = new TimeSpan(hour, minute, 0);
                    DateTime dtPlanNextSite = Convert.ToDateTime(strDate).AddDays(timeBean.transferAddDays + addDays) + tsPlanNext;
                    TimeSpan tsdelay = dtLastSiteArrivaTime - dtPlanNextSite;
                    string outputStr = string.Format("{0}天{1}小时", tsdelay.Days, tsdelay.Hours);
                    globalRoad.strErrorMsg = "错分件 " + arListDifferntSites[1].ToString() + " 错发" + arListDifferntSites[0].ToString();
                    globalRoad.jtDelaySite = arListDifferntSites[1].ToString();
                    globalRoad.jtDelayTime = outputStr;

                }
            }
            catch (Exception ex)
            {

            }
            return isDelay;
        }


        public bool isTransferDelay(string barcode, JArray details, RoadInfo roadInfo, out int res, Hashtable htDbgs)
        {
            int rowIndex = 0;
            res = 0;
            bool isDelay = false;
            try
            {
                ArrayList arListDetails = new ArrayList();
                int count = 0;
                string siteName = "";
                string tmpSite = "";
                string lastSite = "";
                bool isPacelInYizhan = false;
                Hashtable htCurSiteShouldArrival = new Hashtable();
                Hashtable htCurSiteBean = new Hashtable();
                ArrayList arListRoadSites = new ArrayList();
                for (int i = details.Count - 1; i >= 0; i--)
                {
                    JObject jason = (JObject)details[i];
                    arListDetails.Add(jason);
                    count++;
                    string status = jason["status"].ToString();
                    JToken scanNetworkName = jason["scanNetworkName"];
                    JToken scanTypeName = jason["scanTypeName"];
                    string scanTime = jason["scanTime"].ToString();
                    roadInfo.lastScanStatus = status;
                    if (status != "运送中")
                    {
                        continue;
                    }
                    RoadInfo curRoad = new RoadInfo();
                    if (scanNetworkName != null)
                    {
                        lastSite = scanNetworkName.ToString();
                        if (!arListRoadSites.Contains(scanNetworkName.ToString()))
                        {
                            arListRoadSites.Add(scanNetworkName.ToString());
                        }
                        if (!htCurSiteBean.ContainsKey(scanNetworkName.ToString()))
                        {
                            curRoad = new RoadInfo();
                            curRoad.jtSiteName = scanNetworkName.ToString();
                            htCurSiteBean[scanNetworkName.ToString()] = curRoad;
                        }
                        else
                        {
                            curRoad = htCurSiteBean[scanNetworkName.ToString()] as RoadInfo;
                        }
                    }
                    if (scanTypeName != null && (scanTypeName.ToString() == "发件扫描"|| scanTypeName.ToString() == "装车发件"))
                    {
                        curRoad.jtDepTime = Convert.ToDateTime(scanTime);
                        JToken nextStopName = jason["nextStopName"];
                        if (nextStopName != null)
                        {
                            tmpSite = nextStopName.ToString();
                            curRoad.jtNextStopName = tmpSite;
                        }
                    }
                    if (scanTypeName != null && scanTypeName.ToString().Contains("到件"))
                    {
                        curRoad.jtArrivalTime = Convert.ToDateTime(scanTime);
                    }

                }
                if (siteName == "" && isSite(tmpSite))
                {
                    siteName = tmpSite;
                }
                roadInfo.lastSiteName = siteName;
                if (roadInfo.lastSiteName == "")
                {
                    roadInfo.lastSiteName = lastSite;
                }
                Hashtable htNextSiteSholdArrival = new Hashtable();
                string strDelayTime = "";
                foreach (string strSite in arListRoadSites)
                {
                    bool isDepSiteDelay = false;
                    bool isArrSiteDelay = false;
                    if (htCurSiteBean.ContainsKey(strSite))
                    {
                        RoadInfo roadSite = htCurSiteBean[strSite] as RoadInfo;
                        if (roadSite.jtNextStopName != "")
                        {
                            if (isCurSiteDepDelay(roadSite, htNextSiteSholdArrival, out strDelayTime, htDbgs))
                            {

                                if (utility.Utility.isDelayMore(roadInfo.jtDelayTime, strDelayTime))
                                {

                                    if (!isSite(strSite))
                                    {
                                        isDelay = true;
                                        roadInfo.jtDelaySite = strSite;
                                        roadInfo.jtDelayTime = strDelayTime;
                                        roadInfo.jtDepDelayTime = strDelayTime;
                                        roadInfo.strErrorMsg = "" + strSite + " 到件:" + roadSite.jtArrivalTime + " " + " 发件：" + roadSite.jtDepTime + "";
                                        isDepSiteDelay = true;
                                    }

                                }

                            }

                        }
                    }
                }
                string priorSite = "";
                foreach (string strSite in arListRoadSites)
                {
                    RoadInfo roadSite = htCurSiteBean[strSite] as RoadInfo;
                    if (htNextSiteSholdArrival.ContainsKey(strSite))
                    {
                        DateTime dtNextSiteArrivalTime = (DateTime)htNextSiteSholdArrival[strSite];
                        int addAssingDays = getAssignAddDays(roadSite);
                        dtNextSiteArrivalTime = dtNextSiteArrivalTime.AddDays(addAssingDays);
                        if (isCurSiteArrivalDelay(roadSite.jtArrivalTime, dtNextSiteArrivalTime, out strDelayTime))
                        {
                            if (utility.Utility.isDelayMore(roadInfo.jtDelayTime, strDelayTime))
                            {
                                if (!isSite(strSite))
                                {
                                    RoadInfo preSite = htCurSiteBean[priorSite] as RoadInfo;
                                    isDelay = true;
                                    roadInfo.jtDelaySite = strSite;
                                    roadInfo.strErrorMsg = "" + preSite.jtSiteName + " 发件:" + preSite.jtDepTime + " " + strSite + " 到件：" + roadSite.jtArrivalTime + "";
                                    roadInfo.jtDelayTime = strDelayTime;
                                }

                            }

                            //return isDelay;
                        }
                    }
                    priorSite = strSite;
                }

                /*foreach (JObject json in arListDetails)
                {
                    string scanTypeName = json["scanTypeName"].ToString();
                    string scanTime = json["scanTime"].ToString();
                    string scanNetworkName = "";
                    JToken scanSite = json["scanNetworkName"];
                    if (scanSite != null)
                    {
                        scanNetworkName = scanSite.ToString();
                    }
                    roadInfo.lastSacnTime = scanTime;
                    string status = json["status"].ToString();

                    string waybillTrackingContent = json["waybillTrackingContent"].ToString();
                    int code = Convert.ToInt32(json["code"].ToString());
                    if (rowIndex < 2 && scanTypeName == "快件揽收" && code == 10)
                    {
                        roadInfo.lanshouTime = scanTime;
                    }
                    if (status == "已签收" && roadInfo.donePackTime == "")
                    {
                        roadInfo.donePackTime = scanTime;
                    }
                    if (scanNetworkName == siteName)
                    {
                        if (scanTypeName == "到件扫描")
                        {
                            roadInfo.arriveSiteTime = scanTime;
                        }
                        if (status == "派件中" && scanTypeName == "出仓扫描" && roadInfo.assignPackTime == "")
                        {
                            roadInfo.assignPackTime = scanTime;
                        }
                        if (status == "派件中" && scanTypeName == "入库扫描" && roadInfo.yizhanRecTime == "" && waybillTrackingContent.Contains("您的快件已存放至"))
                        {
                            roadInfo.yizhanRecTime = scanTime;
                            if (roadInfo.donePackTime != "" && Convert.ToDateTime(roadInfo.donePackTime) < Convert.ToDateTime(scanTime))
                            {
                                roadInfo.strErrorMsg = "签收后又入驿站";
                                isDelay = true;
                                break;
                            }
                        }
                        if (status == "派件中" && scanTypeName == "入库扫描" && !waybillTrackingContent.Contains("您的快件已存放至"))
                        {
                            isPacelInYizhan = true;
                        }
                    }

                    rowIndex++;

                }*/
                //isDelay = (isAssignDelay(roadInfo) || isYizhanDelay(roadInfo) || isLostParcel(roadInfo));


            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("isParcelDelay ex:" + ex.ToString() + " rowIndex=" + rowIndex.ToString());
            }
            return isDelay;
        }



        public bool isParcelDelay(string barcode, JArray details, RoadInfo roadInfo, out int res)
        {
            int rowIndex = 0;
            res = 0;
            bool isDelay = false;
            try
            {
                ArrayList arListDetails = new ArrayList();
                int count = 0;
                string siteName = "";
                string tmpSite = "";
                string lastSite = "";
                bool isPacelInYizhan = false;
                for (int i = details.Count - 1; i >= 0; i--)
                {

                    JObject jason = (JObject)details[i];
                    arListDetails.Add(jason);
                    count++;
                    string status = jason["status"].ToString();
                    JToken scanNetworkName = jason["scanNetworkName"];
                    JToken scanTypeName = jason["scanTypeName"];
                    roadInfo.lastScanStatus = status;

                    if (scanNetworkName != null)
                    {
                        lastSite = scanNetworkName.ToString();
                    }
                    if (scanNetworkName != null && siteName == "" && status == "派件中")
                    {
                        siteName = scanNetworkName.ToString();
                    }
                    if (scanTypeName != null && (scanTypeName.ToString() == "发件扫描"|| scanTypeName.ToString() == "装车发件"))
                    {
                        JToken nextStopName = jason["nextStopName"];
                        if (nextStopName != null)
                        {
                            tmpSite = nextStopName.ToString();
                        }
                    }
                }
                if (siteName == "" && isSite(tmpSite))
                {
                    siteName = tmpSite;
                }
                roadInfo.lastSiteName = siteName;
                if (roadInfo.lastSiteName == "")
                {
                    roadInfo.lastSiteName = lastSite;
                }

                foreach (JObject json in arListDetails)
                {
                    string scanTypeName = json["scanTypeName"].ToString();
                    string scanTime = json["scanTime"].ToString();
                    string scanNetworkName = "";
                    JToken scanSite = json["scanNetworkName"];
                    if (scanSite != null)
                    {
                        scanNetworkName = scanSite.ToString();
                    }
                    roadInfo.lastSacnTime = scanTime;
                    string status = json["status"].ToString();

                    string waybillTrackingContent = json["waybillTrackingContent"].ToString();
                    int code = Convert.ToInt32(json["code"].ToString());
                    if (rowIndex < 2 && scanTypeName == "快件揽收" && code == 10)
                    {
                        roadInfo.lanshouTime = scanTime;
                    }
                    if (status == "已签收" && roadInfo.donePackTime == "")
                    {
                        roadInfo.donePackTime = scanTime;
                    }
                    if (scanNetworkName == siteName)
                    {
                        if (scanTypeName == "到件扫描"|| scanTypeName == "卸车到件")
                        {
                            roadInfo.arriveSiteTime = scanTime;
                        }
                        if (status == "派件中" && scanTypeName == "出仓扫描" && roadInfo.assignPackTime == "")
                        {
                            roadInfo.assignPackTime = scanTime;
                        }
                        if (status == "派件中" && scanTypeName == "入库扫描" && roadInfo.yizhanRecTime == "" && waybillTrackingContent.Contains("您的快件已存放至"))
                        {
                            roadInfo.yizhanRecTime = scanTime;
                            if (roadInfo.donePackTime != "" && Convert.ToDateTime(roadInfo.donePackTime) < Convert.ToDateTime(scanTime))
                            {
                                roadInfo.strErrorMsg = "签收后又入驿站";
                                isDelay = true;
                                break;
                            }
                        }
                        if (status == "派件中" && scanTypeName == "入库扫描" && !waybillTrackingContent.Contains("您的快件已存放至"))
                        {
                            isPacelInYizhan = true;
                        }
                    }

                    rowIndex++;

                }
                isDelay = (isAssignDelay(roadInfo) || isYizhanDelay(roadInfo) || isLostParcel(roadInfo));


            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("isParcelDelay ex:" + ex.ToString() + " rowIndex=" + rowIndex.ToString());
            }
            return isDelay;
        }

        /// <summary>
        /// 派送超时判断
        /// </summary>
        /// <param name="roadInfo"></param>
        /// <returns></returns>
        private bool isAssignDelay(RoadInfo roadInfo)
        {
            bool res = false;
            try
            {
                if (roadInfo.arriveSiteTime != "" && roadInfo.assignPackTime != "")
                {
                    DateTime dtArrival = Convert.ToDateTime(roadInfo.arriveSiteTime);
                    DateTime dtAssign = Convert.ToDateTime(roadInfo.assignPackTime);
                    TimeSpan ts = dtAssign - dtArrival;
                    if (dtArrival.Hour < 12 && dtAssign.ToShortDateString() != dtArrival.ToShortDateString())
                    {
                        res = true;
                        roadInfo.strErrorMsg = "派送超时";
                    }
                }

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("isAssignDelay ex:" + ex.ToString());
            }
            return res;
        }

        private bool isYizhanDelay(RoadInfo roadInfo)
        {
            bool res = false;
            try
            {
                if (roadInfo.arriveSiteTime != "" && roadInfo.yizhanRecTime != "")
                {
                    DateTime dtArrival = Convert.ToDateTime(roadInfo.arriveSiteTime);
                    DateTime dtYizhan = Convert.ToDateTime(roadInfo.yizhanRecTime);
                    TimeSpan ts = dtYizhan - dtArrival;
                    if (dtArrival.Hour < 12 && dtYizhan.ToShortDateString() != dtArrival.ToShortDateString())
                    {
                        res = true;
                        roadInfo.strErrorMsg = "驿站超时";
                    }
                }

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("isYizhanDelay ex:" + ex.ToString());
            }
            return res;
        }

        private bool isLostParcel(RoadInfo roadInfo)
        {
            bool res = false;
            try
            {
                if (roadInfo.lastScanStatus != "已签收" && roadInfo.yizhanRecTime == "")
                {
                    DateTime dtLastScanTime = Convert.ToDateTime(roadInfo.lastSacnTime);
                    TimeSpan ts = DateTime.Now - dtLastScanTime;
                    if (ts.TotalHours > 48)
                    {
                        roadInfo.strErrorMsg = "遗失";
                        res = true;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("isLostParcel ex:" + ex.ToString());
            }
            return res;
        }

        public bool parseInterceptBarcode(ArrayList arListRoadMap, out string commentType, out string siteCode,out string siteName)
        {
            siteCode = "";
            siteName = "";
            commentType = "";
            bool isDelay = false;
            try
            {
                if(arListRoadMap.Count==0)
                {
                    siteName = "未授权";
                    return isDelay;
                }
                RoadBean road = (RoadBean)arListRoadMap[arListRoadMap.Count - 1];
                if (road.status.Contains("已签收"))
                {
                    commentType = "签收";
                    siteCode = road.scanNetworkCode;
                    siteName = road.scanNetworkName;
                    if (siteCode=="")
                    {
                        siteCode = road.scanStieWorkID;
                    }
                    if(siteCode=="")
                    {
                        for (int i = arListRoadMap.Count - 1; i > 0; i--)
                        {
                            RoadBean curRoad = (RoadBean)arListRoadMap[i];
                            if (curRoad.scanTypeName == "到件扫描"|| curRoad.scanTypeName == "卸车到件")
                            {
                                siteCode = curRoad.scanNetworkCode;
                                siteName = road.scanNetworkName;
                                break;
                            }
                        }
                    }
                    return false;
                }
                bool hasSigned = false;
                bool isReturnParcel = false;
                bool hasAssigned = false;
                string assignedSiteName = "";
                string lastScanTypeName = "";
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean curRoad = (RoadBean)arListRoadMap[i];
                    string status = road.status;
                    if (curRoad.status.Contains("派件中"))
                    {
                        hasAssigned = true;
                        if(road.scanNetworkName!="")
                        {
                            assignedSiteName = road.scanNetworkName;
                            lastScanTypeName = road.scanTypeName;
                        }
                        
                    }
                    /*if (status.Contains("已签收"))
                    {
                        hasSigned = true;
                    }
                    if (curRoad.scanTypeName != null && curRoad.scanTypeName.ToString() == "退件登记")
                    {
                        isReturnParcel = true;
                    }*/
                }

                /*if (hasSigned && !isReturnParcel)
                {
                    return false;
                }*/
                if(road.scanNetworkName == "")
                {
                    for(int i= arListRoadMap.Count-1;i>0;i--)
                    {
                        RoadBean curRoad = (RoadBean)arListRoadMap[i];
                        if(curRoad.scanTypeName=="到件扫描"|| curRoad.scanTypeName == "卸车到件")
                        {
                            road = curRoad;
                            break;
                        }
                    }

                }
                if (road.scanNetworkName == StoParams.Instance.register_site)
                {
                    if (road.scanTypeName != null && (road.scanTypeName == "拦截件登记" || road.scanTypeName == "退件登记" || road.scanTypeName == "问题件扫描" || road.scanTypeName == "拦截件撤销" || road.scanTypeName == "退件撤销"))
                    {
                        for (int i = 0; i < arListRoadMap.Count; i++)
                        {
                            RoadBean curRoad = (RoadBean)arListRoadMap[i];

                            if (curRoad.scanNetworkName != StoParams.Instance.register_site)
                            {
                                road = (RoadBean)arListRoadMap[i];
                            }
                        }
                    }

                    else if (road.scanTypeName != "发件扫描" && road.scanTypeName != "装车发件")
                    {
                        return false;
                    }

                }


                JToken scanTypeName = road.scanTypeName;
                string scanTime = road.scanTime;
                string scanNetCode = road.scanNetworkCode;
                TimeSpan ts = System.DateTime.Now - Convert.ToDateTime(scanTime);
                siteCode = road.scanNetworkCode;
                if(siteCode=="")
                {
                    siteCode = road.scanStieWorkID;
                }
                siteName = road.scanNetworkName;
                if (scanTypeName.ToString().Contains("发件"))
                {
                    if (road.nextStopName != null)
                    {
                        siteCode = road.nextNetworkCode;
                        if(road.nextNetworkCode=="")
                        {
                            siteCode = road.nextStopWorkID;
                        }
                        siteName = road.nextStopName;
                    }
                }

                if (scanTypeName.ToString().Contains("到件") || scanTypeName.ToString().Contains("发件"))
                {
                    if (road.scanNetworkName.Contains("转运中心") || road.scanNetworkName.Contains("集散"))
                    {

                        //if (ts.TotalHours > 24)
                        {
                            if (road.nextStopName != null && road.nextStopName.Contains("网点"))
                            {

                                commentType = "派件";
                            }
                            else
                            {
                                commentType = "中转";
                            }

                            return true;
                        }
                    }
                    else if (road.scanNetworkName.Contains("网点"))
                    {
                        //if (ts.TotalHours > 48)
                        {
                            commentType = "派件";
                            return true;
                        }
                    }
                }

                if (road.status.Contains("派件中"))
                {
                    //if (ts.TotalHours > 24)
                    {
                        if (road.scanTypeName == "出仓扫描")
                        {
                            commentType = "派件";
                            return true;
                        }
                        else
                        {
                            commentType = "签收";
                            return true;
                        }

                    }
                }

                if (road.scanTypeName == "完结" && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site && road.waybillTrackingContent.Contains("超时未签收"))
                {
                    //if (ts.TotalHours > 24)
                    {
                        if (hasAssigned && assignedSiteName == road.scanNetworkName)
                        {
                            if (lastScanTypeName == "出仓扫描")
                            {
                                commentType = "派件";
                            }
                            else
                            {
                                commentType = "签收";
                            }
                        }
                        else
                        {
                            commentType = "派件";
                        }
                    }
                       
                }

                /*for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean road = (RoadBean)arListRoadMap[i];
                    string status = road.status;
                    JToken scanNetworkName = road.scanNetworkName;
                    JToken scanTypeName = road.scanTypeName;
                    string scanTime = road.scanTime;
                }*/

            }
            catch (Exception ex)
            {

            }
            return isDelay;
        }




        public bool parseAutoBarcode(ArrayList arListRoadMap,out string commentType,out string siteCode)
        {
            siteCode = "";
            commentType = "";
            bool isDelay = false;
            try
            {
                RoadBean road = (RoadBean)arListRoadMap[arListRoadMap.Count-1];
                if(road.status.Contains("已签收"))
                {
                    return false;
                }
                bool hasSigned = false;
                bool isReturnParcel = false;
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean curRoad = (RoadBean)arListRoadMap[i];
                    string status = road.status;
                    if(status.Contains("已签收"))
                    {
                        hasSigned = true;
                    }
                    if (curRoad.scanTypeName != null && curRoad.scanTypeName.ToString() == "退件登记")
                    {
                        isReturnParcel = true;
                    }
                }

                if(hasSigned&&!isReturnParcel)
                {
                    return false;
                }
                if(road.scanNetworkName==StoParams.Instance.register_site)
                {
                    if(road.scanTypeName != null && (road.scanTypeName == "拦截件登记"|| road.scanTypeName == "退件登记" || road.scanTypeName == "问题件扫描"))
                    {
                        for (int i = 0; i < arListRoadMap.Count; i++)
                        {
                            RoadBean curRoad = (RoadBean)arListRoadMap[i];
                           
                            if (curRoad.scanNetworkName!= StoParams.Instance.register_site)
                            {
                                road = (RoadBean)arListRoadMap[i];
                            }
                        }
                    }
                   
                    else if(road.scanTypeName != "发件扫描" && road.scanTypeName != "装车发件")
                    {
                        return false;
                    }
                   
                }
            

                JToken scanTypeName = road.scanTypeName;
                string scanTime = road.scanTime;
                string scanNetCode = road.scanNetworkCode;
                TimeSpan ts = System.DateTime.Now - Convert.ToDateTime(scanTime);
                siteCode = road.scanNetworkCode;
                if (scanTypeName.ToString().Contains("发件"))
                {
                    if (road.nextStopName != null)
                    {
                        siteCode = road.nextNetworkCode;
                    }
                }

                if (scanTypeName.ToString().Contains("到件")|| scanTypeName.ToString().Contains("发件"))
                {
                    if(road.scanNetworkName.Contains("转运中心")|| road.scanNetworkName.Contains("集散"))
                    {
                       
                        if(ts.TotalHours>24)
                        {
                            if (road.nextStopName != null && road.nextStopName.Contains("网点"))
                            {
                                
                                commentType = "派件";
                            }
                            else
                            {
                                commentType = "中转";
                            }
                           
                            return true;
                        }
                    }
                    else if(road.scanNetworkName.Contains("网点"))
                    {
                        if (ts.TotalHours > 48)
                        {
                            commentType = "派件";
                            return true;
                        }
                    }
                }

                if (road.status.Contains("派件中"))
                {
                    if (ts.TotalHours > 24)
                    {
                        if(road.scanTypeName=="出仓扫描")
                        {
                            commentType = "派件";
                            return true;
                        }
                        else
                        {
                            commentType = "签收";
                            return true;
                        }
                        
                    }
                }

                if (road.scanTypeName == "问题件扫描" && road.scanNetworkName.Contains("网点")&& road.scanNetworkName != StoParams.Instance.register_site)
                {                   
                    if (ts.TotalHours > 24)
                    {
                        commentType = "派件";
                        return true;

                    }
                }
               

                /*for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean road = (RoadBean)arListRoadMap[i];
                    string status = road.status;
                    JToken scanNetworkName = road.scanNetworkName;
                    JToken scanTypeName = road.scanTypeName;
                    string scanTime = road.scanTime;
                }*/

            }
            catch (Exception ex)
            {

            }
            return isDelay;
        }



        public string getCusRecvMsg(RoadBean road)
        {
            //string res = "核实未收到，虚假签收。请帮忙尽快处理。";
            string res = "核实未收到，请帮忙尽快核实。";
            try
            {
                string dateTime = road.scanTime;
                DateTime dtSacn = Convert.ToDateTime(dateTime);
                DateTime date = dtSacn.Date;
                res = "延误仲裁查件，此件" + date.Month.ToString() + "月" + date.Day.ToString() + "号录签收," + res;
                if (StoParams.Instance.register_site.Contains("阳江")|| StoParams.Instance.register_site.Contains("太和"))
                {
                    DateTime dtNow = System.DateTime.Now;
                    res = "遗失仲裁查件： 客户反馈显示签收实际未收到，";

                }
                res = res + " 请提供签收底单";


            }
            catch(Exception ex)
            {

            }
            return res;
        }

        public string getTransferMsg(RoadBean road,string siteName, ArrayList arListRoadMap)
        {
            string res = "，客户一直未收到，请帮忙尽快核实。";
            try
            {
                string dateTime = road.scanTime;
                DateTime dtSacn = Convert.ToDateTime(dateTime);
                DateTime date = dtSacn.Date;
                
                if (road.scanTypeName.Contains("到件"))
                {
                    res = "延误仲裁查件,此件" + date.Month.ToString() + "月" + date.Day.ToString() + "号到件" + road.scanNetworkName + res;
                }
                else if(road.scanTypeName.Contains("发件"))
                {
                    res = "延误仲裁查件,此件" + date.Month.ToString() + "月" + date.Day.ToString() + "号扫描给" + road.nextStopName + res;
                }
                else
                {
                    for(int i= arListRoadMap.Count-1;i>0;i--)
                    {
                        RoadBean road1 = (RoadBean)arListRoadMap[i];
                        if (road1.scanNetworkName == siteName && road1.scanTypeName.Contains("到件"))
                        {
                            road = (RoadBean)arListRoadMap[i];
                            date = Convert.ToDateTime(road.scanTime);
                            break;
                        }
                    }
                    res = "延误仲裁查件,此件" + date.Month.ToString() + "月" + date.Day.ToString() + "号到件" + road.scanNetworkName + res;
                }


                if (StoParams.Instance.register_site.Contains("阳江")|| StoParams.Instance.register_site.Contains("太和"))
                {
                    DateTime dtNow = System.DateTime.Now;

                    if (road.scanTypeName.Contains("到件"))
                    {
                        res = "遗失仲裁查件,此件" + date.Day.ToString() + "号到件" + road.scanNetworkName + " " + dtNow.Day.ToString() + " 号一直无记录，核实客户未收到此件，请帮忙尽快核实";
                    }
                    else if (road.scanTypeName.Contains("发件"))
                    {
                        res = "遗失仲裁查件,此件" + date.Day.ToString() + "号扫描给" + road.nextStopName + " " + dtNow.Day.ToString() + " 号一直无记录，核实客户未收到此件，请帮忙尽快核实";
                    }
                    else
                    {
                        for (int i = arListRoadMap.Count - 1; i > 0; i--)
                        {
                            RoadBean road1 = (RoadBean)arListRoadMap[i];
                            if (road1.scanNetworkName == siteName && road1.scanTypeName.Contains("到件"))
                            {
                                road = (RoadBean)arListRoadMap[i];
                                date = Convert.ToDateTime(road.scanTime);
                                break;
                            }
                        }
                        res = "遗失仲裁查件,此件" + date.Day.ToString() + "号到件" + road.scanNetworkName + " " + dtNow.Day.ToString() + " 号一直无记录，核实客户未收到此件，请帮忙尽快核实";;
                    }

             
                }



                //res = "延误仲裁查件，此件" + date.Month.ToString() + "月" + date.Day.ToString() + "号扫描给"+ siteName + res;
            }
            catch (Exception ex)
            {

            }
            return res;
        }

        public string getDispatchMsg(RoadBean road,bool isLastInWh)
        {
            //string res = "，麻烦尽快通知客户取件。";
            string res = "，请帮忙尽快核实。";
            try
            {
                string dateTime = road.scanTime;
                DateTime dtSacn = Convert.ToDateTime(dateTime);
                DateTime date = dtSacn.Date;
                if(!isLastInWh)
                {
                    res = "，核实客户未收到，请帮忙尽快核实。";
                }
             
                if(!road.scanTypeName.Contains("发件"))
                {
                    res = "延误仲裁查件,此件" + date.Month.ToString() + "月" + date.Day.ToString() + "号到件" + road.scanNetworkName + res;
                }
                else
                {
                    res = "延误仲裁查件,此件" + date.Month.ToString() + "月" + date.Day.ToString() + "号扫描给" + road.nextStopName + res;
                }
                if(StoParams.Instance.register_site.Contains("阳江"))
                {
                    DateTime dtNow = System.DateTime.Now;
                    if (!road.scanTypeName.Contains("发件"))
                    {
                        res = "遗失仲裁查件,此件" +  date.Day.ToString() + "号到件" + road.scanNetworkName +" "+ dtNow.Day.ToString()+" 号一直无记录，核实客户未收到此件，请帮忙尽快核实";
                    }
                    else
                    {
                        res = "遗失仲裁查件,此件"  + date.Day.ToString() + "号扫描给" + road.nextStopName + " " + dtNow.Day.ToString() + " 号一直无记录，核实客户未收到此件，请帮忙尽快核实";
                    }
                }
               
            }
            catch (Exception ex)
            {

            }
            return res;
        }

        public string getInterMsg(string commentType,string oriaddr)
        {
            string res = "遗失仲裁查件，此件客户要求拦截，请勿派送！我司已发起退件拦截，请帮忙操作退回，";


            if (commentType.Contains("签收"))
            {
                res = "遗失仲裁查件，客户反馈显示签收实际未收到，找到请退回，";
            }
            else
            {
                res = "遗失仲裁查件，核实客户未收到！我司已发起退件拦截，请帮忙操作退回，";
            }
            /*if(oriaddr.Length>10)
            {
                res = "遗失仲裁查件，此件客户要求拦截，请勿派送！我司已发起退件拦截，请帮忙操作退回，";
            }*/
            if (StoParams.Instance.register_site.Contains("阳江"))
            {
                if(commentType.Contains("签收"))
                {
                    res = "遗失仲裁查件，客户反馈显示签收实际未收到，找到请退回，";
                }
                else
                {
                    res = "遗失仲裁查件，此件客户未收到，要求退回也一直未退回，请尽快核实，";
                }
                
            }

            
            
            return res;
        }


        public string getYishiMsgQianshou()
        {
            string res = "遗失仲裁查件，客户反馈显示签收，实际未收到，找到请退回。";            
            return res;
        }

        public string getGuifanYishiMsg()
        {
            string res = "遗失仲裁查件，规范拦截未退回，追责遗失责任。";
            return res;
        }

        public string getYishiMsgTransfer(RoadBean road)
        {
            string res = "遗失仲裁查件,";
            try
            {
                string dateTime = road.scanTime;
                DateTime dtSacn = Convert.ToDateTime(dateTime);
                DateTime date = dtSacn.Date;
                res = "遗失仲裁查件，此件" + date.Day.ToString() + "号到" + System.DateTime.Now.Date.ToString() + "号一直无记录，核实客户一直未收到此件，请尽快帮忙核实。";
            }
            catch (Exception ex)
            {

            }
            return res;
        }




        public void parseManualBarcode4DispatchDelay(ArrayList arListRoadMap, out string commentType,
    out string siteID, out string siteName, out string leaveMsg, bool isYishi = false)
        {
            siteID = "";
            commentType = "";
            siteName = "";
            leaveMsg = "";
            bool isLastInWh = false;
            try
            {
                RoadBean road = (RoadBean)arListRoadMap[arListRoadMap.Count - 1];

                bool hasSigned = false;
                bool hasAssigned = false;
                string assignedSiteName = "";
                string lastScanTypeName = "";


                bool isReturnParcel = false;
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean curRoad = (RoadBean)arListRoadMap[i];
                    string status = road.status;
                    if (status.Contains("已签收"))
                    {
                        hasSigned = true;
                        hasAssigned = true;
                        leaveMsg = getCusRecvMsg(curRoad);
                    }
                    if (curRoad.scanTypeName != null && curRoad.scanTypeName.ToString() == "退件登记")
                    {
                        isReturnParcel = true;
                    }
                    if (road.status.Contains("派件中"))
                    {
                        lastScanTypeName = road.scanTypeName;
                        assignedSiteName = road.scanNetworkName;
                    }
                }


                if (road.scanNetworkName == "")
                {
                    bool findCurRec = false;
                    if (road.scanNetworkName == "" || road.scanNetworkName == StoParams.Instance.register_site)
                    {
                        for (int i = arListRoadMap.Count - 1; i > 0; i--)
                        {
                            RoadBean curRoad = (RoadBean)arListRoadMap[i];
                            if (curRoad.scanTypeName == "问题件扫描" && curRoad.scanNetworkName != "" && curRoad.scanNetworkName != StoParams.Instance.register_site)
                            {
                                findCurRec = true;
                                road = curRoad;
                                break;
                            }
                            if ((curRoad.scanTypeName == "到件扫描" || curRoad.scanTypeName == "出仓扫描" || curRoad.scanTypeName == "卸车到件"))
                            {
                                findCurRec = true;
                                road = curRoad;
                                break;
                            }
                        }
                    }
                    else
                    {
                        for (int i = arListRoadMap.Count - 1; i > 0; i--)
                        {
                            RoadBean curRoad = (RoadBean)arListRoadMap[i];
                            if ((curRoad.scanTypeName == "到件扫描" || curRoad.scanTypeName == "出仓扫描" || curRoad.scanTypeName == "卸车到件") && road.scanNetworkName == curRoad.scanNetworkName)
                            {
                                findCurRec = true;
                                road = curRoad;
                                break;
                            }
                        }
                    }

                    if (!findCurRec)
                    {
                        for (int i = arListRoadMap.Count - 1; i > 0; i--)
                        {
                            RoadBean curRoad = (RoadBean)arListRoadMap[i];
                            if (curRoad.scanTypeName.Contains("发件") && road.scanNetworkName == curRoad.nextStopName)
                            {
                                road = curRoad;
                                break;
                            }
                        }

                    }

                }

                if (road.scanNetworkName == StoParams.Instance.register_site)
                {
                    if (road.scanTypeName != null && (road.scanTypeName == "拦截件登记" || road.scanTypeName == "退件登记" || road.scanTypeName == "问题件扫描" || road.scanTypeName == "拦截件撤销" || road.scanTypeName == "退件撤销"))
                    {
                        for (int i = 0; i < arListRoadMap.Count; i++)
                        {
                            RoadBean curRoad = (RoadBean)arListRoadMap[i];

                            if (curRoad.scanNetworkName != StoParams.Instance.register_site)
                            {
                                road = (RoadBean)arListRoadMap[i];
                            }
                        }
                    }

                    else if (road.scanTypeName != "发件扫描" && road.scanTypeName != "装车发件")
                    {

                    }

                }

                if(!road.scanNetworkName.Contains("网点")|| road.scanNetworkName== StoParams.Instance.register_site)
                {
                    //return;
                }
                JToken scanTypeName = road.scanTypeName;
                string scanTime = road.scanTime;
                string scanNetCode = road.scanNetworkCode;
                if (scanNetCode == "")
                {
                    scanNetCode = road.scanStieWorkID;

                }
                TimeSpan ts = System.DateTime.Now - Convert.ToDateTime(scanTime);
                siteID = road.scanStieWorkID;

                siteName = road.scanNetworkName;
                if (scanTypeName.ToString().Contains("发件"))
                {
                    if (road.nextStopName != null)
                    {
                        siteID = road.nextStopWorkID;
                        siteName = road.nextStopName;
                    }
                }

                if (scanTypeName.ToString().Contains("到件") || scanTypeName.ToString().Contains("发件"))
                {
                    if (road.scanNetworkName.Contains("转运中心") || road.scanNetworkName.Contains("集散"))
                    {

                        if (road.nextStopName != null && road.nextStopName.Contains("网点"))
                        {

                            commentType = "中转";
                        }
                        else
                        {
                            commentType = "中转";
                        }
                    }
                    else if (road.scanNetworkName.Contains("网点"))
                    {
                        commentType = "派件";
                    }
                }

                if (road.status.Contains("派件中"))
                {
                    if (road.scanTypeName == "出仓扫描" || road.scanTypeName == "出库扫描")
                    {
                        commentType = "派件";
                    }
                    else
                    {
                        commentType = "签收";
                    }
                }
                if (road.status.Contains("已签收"))
                {
                    commentType = "签收";
                }
                else if (road.scanTypeName == "问题件扫描" && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site)
                {
                    commentType = "派件";
                }
                else if (road.scanTypeName == "问题件扫描" && !road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site)
                {
                    commentType = "中转";
                }
                else if (road.scanTypeName == "快件取出扫描" && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site)
                {
                    commentType = "派件";
                }
                else if ((road.scanTypeName == "入仓扫描" || road.scanTypeName == "入库扫描") && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site)
                {
                    isLastInWh = true;
                    commentType = "派件";
                }
                else if ((road.scanTypeName == "出仓扫描" || road.scanTypeName == "出库扫描") && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site)
                {
                    commentType = "派件";
                }
                else if (road.scanTypeName == "完结" && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site && road.waybillTrackingContent.Contains("超时未签收"))
                {
                    if (hasAssigned && assignedSiteName == road.scanNetworkName)
                    {
                        if (lastScanTypeName == "出仓扫描" || lastScanTypeName == "出库扫描")
                        {
                            commentType = "派件";
                        }
                        else
                        {
                            commentType = "签收";
                        }
                    }
                    else
                    {
                        commentType = "派件";
                    }
                }
                if (commentType == "中转")
                {
                    leaveMsg = getTransferMsg(road, siteName, arListRoadMap);
                }
                else if (commentType == "派件")
                {
                    leaveMsg = getDispatchMsg(road, isLastInWh);
                }
                else if (commentType == "签收")
                {
                    leaveMsg = getCusRecvMsg(road);
                }
                else
                {
                    leaveMsg = getTransferMsg(road, siteName, arListRoadMap);
                }

                if (isYishi)
                {
                    if (commentType == "签收")
                    {
                        leaveMsg = getYishiMsgQianshou();
                    }
                    else
                    {
                        leaveMsg = getYishiMsgTransfer(road);
                    }
                }


            }
            catch (Exception ex)
            {

            }

        }



        public bool isLanshouDone(ArrayList arListRoadMap)
        {
            bool isLanshou = false;
            try
            {
                foreach (RoadBean road in arListRoadMap)
                {
                    if(road.scanTypeName.Contains("揽收")|| road.scanTypeName.Contains("入仓"))
                    {
                        isLanshou = true;
                        break;
                    }
                }
            }
            catch(Exception ex)
            {

            }
            return isLanshou;
        }
        public void parseInboundManualBarcode(string barcode,out string siteID, out string siteNam)
        {
            siteID = "";
   
            siteNam = "";
            try
            {
                string strUrl = "https://jmsgw.jtexpress.com.cn/sqsthird/comboBox/getReceiverNetwork?waybillNo=" + barcode;
                JObject jObj = new JObject();

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string resMsg = BarcodeDelay.HttpClient.HttpUtil.Instance.QueryCommon(strUrl, postData, "GET", "batchProblem");


                JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                JArray dataObj = (JArray)jsonObjRes["data"];
                JObject siteObj = (JObject)dataObj[dataObj.Count - 1];
                siteID = siteObj["id"].ToString();
                siteNam= siteObj["name"].ToString();


            }
            catch(Exception ex)
            {

            }
            return;


        }



        public void parseManualBarcode(ArrayList arListRoadMap, out string commentType,
            out string siteID, out string siteName, out string leaveMsg, bool isYishi = false, bool isCui = false)
        {
            siteID = "";
            commentType = "";
            siteName = "";
            leaveMsg = "";
            bool isLastInWh = false;
            try
            {
                RoadBean road = (RoadBean)arListRoadMap[arListRoadMap.Count - 1];

                bool hasSigned = false;
                bool hasAssigned = false;
                string assignedSiteName = "";
                string lastScanTypeName = "";


                bool isReturnParcel = false;
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean curRoad = (RoadBean)arListRoadMap[i];
                    string status = road.status;
                    if (status.Contains("已签收") || curRoad.waybillTrackingContent.Contains("已签收"))
                    {
                        hasSigned = true;
                        hasAssigned = true;
                        leaveMsg = getCusRecvMsg(curRoad);
                    }
                    if (curRoad.scanTypeName != null && curRoad.scanTypeName.ToString() == "退件登记")
                    {
                        isReturnParcel = true;
                    }
                    if (road.status.Contains("派件中"))
                    {
                        lastScanTypeName = road.scanTypeName;
                        /*if (road.scanTypeName == "出仓扫描")
                        {
                            commentType = "派件";
                        }
                        else
                        {
                            commentType = "签收";
                        }*/
                        hasAssigned = true;
                        assignedSiteName = road.scanNetworkName;
                    }
                }
                if (road.scanNetworkName == "" || road.waybillTrackingContent.Contains("超时未签收"))
                {
                    bool findCurRec = false;
                    if (road.scanNetworkName == "" || road.scanNetworkName == StoParams.Instance.register_site)
                    {
                        for (int i = arListRoadMap.Count - 1; i > 0; i--)
                        {
                            RoadBean curRoad = (RoadBean)arListRoadMap[i];
                            if (curRoad.scanTypeName == "问题件扫描" && curRoad.scanNetworkName != "" && curRoad.scanNetworkName != StoParams.Instance.register_site)
                            {
                                findCurRec = true;
                                road = curRoad;
                                break;
                            }
                            if ((curRoad.scanTypeName == "到件扫描" || curRoad.scanTypeName == "出仓扫描" || curRoad.scanTypeName == "卸车到件"))
                            {
                                findCurRec = true;
                                road = curRoad;
                                break;
                            }
                            if ((curRoad.scanTypeName == "装车发件"))
                            {
                                findCurRec = true;
                                road = curRoad;
                                break;
                            }
                        }
                    }
                    else
                    {
                        for (int i = arListRoadMap.Count - 1; i > 0; i--)
                        {
                            RoadBean curRoad = (RoadBean)arListRoadMap[i];
                            if ((curRoad.scanTypeName == "到件扫描" || curRoad.scanTypeName == "出仓扫描" || curRoad.scanTypeName == "卸车到件") && road.scanNetworkName == curRoad.scanNetworkName)
                            {
                                findCurRec = true;
                                road = curRoad;
                                break;
                            }
                        }
                    }

                    if (!findCurRec)
                    {
                        for (int i = arListRoadMap.Count - 1; i > 0; i--)
                        {
                            RoadBean curRoad = (RoadBean)arListRoadMap[i];
                            if (curRoad.scanTypeName.Contains("发件") && road.scanNetworkName == curRoad.nextStopName)
                            {
                                road = curRoad;
                                break;
                            }
                        }

                    }

                }


                if (road.scanNetworkName == StoParams.Instance.register_site)
                {
                    if (road.scanTypeName != null && (road.scanTypeName == "拦截件登记" || road.scanTypeName == "退件登记" || road.scanTypeName == "问题件扫描" || road.scanTypeName == "拦截件撤销" || road.scanTypeName == "退件撤销"))
                    {
                        for (int i = 0; i < arListRoadMap.Count; i++)
                        {
                            RoadBean curRoad = (RoadBean)arListRoadMap[i];

                            if (curRoad.scanNetworkName != StoParams.Instance.register_site && curRoad.scanStieWorkID != "")
                            {
                                road = (RoadBean)arListRoadMap[i];
                            }
                        }
                    }

                    else if (road.scanTypeName != "发件扫描" && road.scanTypeName != "装车发件")
                    {

                    }

                }


                JToken scanTypeName = road.scanTypeName;
                string scanTime = road.scanTime;
                string scanNetCode = road.scanNetworkCode;
                if (scanNetCode == "")
                {
                    scanNetCode = road.scanStieWorkID;

                }
                TimeSpan ts = System.DateTime.Now - Convert.ToDateTime(scanTime);
                siteID = road.scanStieWorkID;

                siteName = road.scanNetworkName;
                if (scanTypeName.ToString().Contains("发件"))
                {
                    if (UtilityHelp.Instance.isNeedResetNestStopNetID(road, isCui))
                    {

                        if (road.nextStopName != null)
                        {
                            siteID = road.nextStopWorkID;
                            siteName = road.nextStopName;
                        }
                    }

                }
                if (siteID == "" && siteName == "")
                {
                    for (int i = arListRoadMap.Count - 1; i > 0; i--)
                    {
                        RoadBean curRoad = (RoadBean)arListRoadMap[i];
                        if (curRoad.scanNetworkName != StoParams.Instance.register_site && curRoad.scanStieWorkID != "")
                        {
                            road = (RoadBean)arListRoadMap[i];
                            scanTypeName = curRoad.scanTypeName;
                            siteID = road.scanStieWorkID;
                            siteName = road.scanNetworkName;
                            scanNetCode = road.scanNetworkCode;
                            break;
                        }
                    }
                    if (scanTypeName.ToString().Contains("发件"))
                    {
                        if (UtilityHelp.Instance.isNeedResetNestStopNetID(road, isCui))
                        {
                            if (road.nextStopName != null)
                            {
                                siteID = road.nextStopWorkID;
                                siteName = road.nextStopName;
                                scanNetCode = road.nextNetworkCode;
                            }
                        }

                    }
                    if (scanNetCode == "")
                    {
                        scanNetCode = siteID;

                    }
                }

                if (scanTypeName.ToString().Contains("到件") || scanTypeName.ToString().Contains("发件"))
                {
                    if (road.scanNetworkName.Contains("转运中心") || road.scanNetworkName.Contains("集散"))
                    {

                        if (road.nextStopName != null && road.nextStopName.Contains("网点"))
                        {

                            commentType = "中转";
                        }
                        else
                        {
                            commentType = "中转";
                        }
                    }
                    else if (road.scanNetworkName.Contains("网点"))
                    {
                        commentType = "派件";
                    }
                }

                if (road.status.Contains("派件中"))
                {
                    if (road.scanTypeName == "出仓扫描" || road.scanTypeName == "出库扫描" || road.scanTypeName == "入库扫描")
                    {
                        commentType = "派件";
                    }
                    else
                    {
                        commentType = "签收";
                    }
                }
                if (road.status.Contains("已签收") || road.waybillTrackingContent.Contains("已签收"))
                {
                    commentType = "签收";
                }
                else if (road.scanTypeName == "问题件扫描" && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site)
                {
                    commentType = "派件";
                }
                else if (road.scanTypeName == "问题件扫描" && !road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site)
                {
                    commentType = "中转";
                }
                else if (road.scanTypeName == "快件取出扫描" && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site)
                {
                    commentType = "派件";
                }
                else if ((road.scanTypeName == "入仓扫描" || road.scanTypeName == "入库扫描") && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site)
                {
                    isLastInWh = true;
                    commentType = "派件";
                }
                else if ((road.scanTypeName == "出仓扫描" || road.scanTypeName == "出库扫描") && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site)
                {
                    commentType = "派件";
                }
                else if (road.scanTypeName == "完结" && road.scanNetworkName.Contains("网点") && road.scanNetworkName != StoParams.Instance.register_site && road.waybillTrackingContent.Contains("超时未签收"))
                {
                    if (hasAssigned && assignedSiteName == road.scanNetworkName)
                    {
                        if (lastScanTypeName == "出仓扫描" || lastScanTypeName == "出库扫描")
                        {
                            commentType = "派件";
                        }
                        else
                        {
                            commentType = "签收";
                        }
                    }
                    else
                    {
                        commentType = "派件";
                    }
                }

                if (hasSigned)
                {
                    commentType = "签收";
                }
                if (commentType == "中转")
                {
                    leaveMsg = getTransferMsg(road, siteName, arListRoadMap);
                }
                else if (commentType == "派件")
                {
                    leaveMsg = getDispatchMsg(road, isLastInWh);
                }
                else if (commentType == "签收")
                {
                    leaveMsg = getCusRecvMsg(road);
                }
                else
                {
                    leaveMsg = getTransferMsg(road, siteName, arListRoadMap);
                }

                if (isYishi)
                {
                    if (commentType == "签收")
                    {
                        leaveMsg = getYishiMsgQianshou();
                    }
                    else
                    {
                        leaveMsg = getYishiMsgTransfer(road);
                    }
                }


            }
            catch (Exception ex)
            {

            }

        }



        public bool isInterceptDelay(ArrayList arListRoadMap)
        {
            bool isDelay = false;
            try
            {
                int returnIndex = 0;
                int cancelReturnIndex = 0;
                string interCeptTime = "";

                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean curRoad = (RoadBean)arListRoadMap[i];
                    if(curRoad.scanTypeName== "退件登记"&& curRoad.scanNetworkName== StoParams.Instance.register_site)
                    {
                        returnIndex = i;
                        interCeptTime = curRoad.scanTime;
                    }
                    if (curRoad.scanTypeName == "拦截件登记" && curRoad.scanNetworkName == StoParams.Instance.register_site
                        && curRoad.waybillTrackingContent.Contains("退回件"))
                    {
                        returnIndex = i;
                        interCeptTime = curRoad.scanTime;
                    }
                    if (curRoad.scanTypeName == "退件撤销" && curRoad.scanNetworkName == StoParams.Instance.register_site)
                    {
                        cancelReturnIndex = i;
                    }
                }
                if(returnIndex< cancelReturnIndex)
                {
                    return isDelay;
                }
                if(returnIndex==0)
                {
                    //无拦截撤销
                    return isDelay;
                }
                //有拦截撤销
                RoadBean road = (RoadBean)arListRoadMap[arListRoadMap.Count - 1];
                if (road.status.Contains("已签收") && road.scanNetworkName == StoParams.Instance.register_site)
                {
                    return isDelay;
                }
                if (road.status.Contains("已签收")&& road.scanNetworkName!= StoParams.Instance.register_site)
                {
                    string signTime = road.scanTime;
                    TimeSpan tsSignSite = System.DateTime.Now - Convert.ToDateTime(signTime);
                    if(tsSignSite.TotalDays>2)
                    {
                        isDelay = true;
                    }
                }
                else if (road.status.Contains("完结") && road.scanNetworkName == StoParams.Instance.register_site&&road.waybillTrackingContent.Contains("超时未签收"))
                {
                    road = (RoadBean)arListRoadMap[arListRoadMap.Count - 2];
                    string signTime = road.scanTime;
                    TimeSpan tsSignSite = System.DateTime.Now - Convert.ToDateTime(signTime);
                    if (tsSignSite.TotalDays > 2)
                    {
                        isDelay = true;
                    }
                }
                else
                {
                    string lastScantime = road.scanTime;
                    TimeSpan tsSignSite = System.DateTime.Now - Convert.ToDateTime(lastScantime);
                    if (road.scanNetworkName != StoParams.Instance.register_site)
                    {
                        if (tsSignSite.TotalDays > 2)
                        {
                            isDelay = true;
                        }
                    }
                    else if(road.scanTypeName== "拦截件扫描"|| road.scanTypeName == "拦截件登记" || road.scanTypeName == "退件登记")
                    {
                        if (tsSignSite.TotalDays > 2)
                        {
                            isDelay = true;
                        }
                    }
                }


            }
            catch (Exception ex)
            {

            }
            return isDelay;
        }


        public bool isOnlySelfSiteMap(ArrayList arListRoadMap)
        {
            bool res = false;
            Hashtable htSites = new Hashtable();
            try
            {
                
                foreach(RoadBean road in arListRoadMap)
                {
                    if(road.scanStieWorkID!="")
                    {
                        htSites[road.scanStieWorkID] = "";
                    }
                }
            }
            catch(Exception ex)
            {

            }
            if(htSites.Count==1)
            {
                res = true;
            }
            return res;

        }




        public bool isNoSiteToLeaveMsg(ArrayList arListRoadMap,string pickName)
        {
            bool res = true;
            Hashtable htSites = new Hashtable();
            try
            {
                string siteName = "";
                if(MemberInfo.Instance.htLeaveMsgOmitSiteMap.ContainsKey(pickName))
                {
                    siteName = MemberInfo.Instance.htLeaveMsgOmitSiteMap[pickName].ToString();
                }
                RoadBean roadBean = new RoadBean();
                ArrayList arListSites = new ArrayList();
                foreach (RoadBean road in arListRoadMap)
                {
                    if(road.scanNetworkName==pickName)
                    {
                        continue;
                    }
                    roadBean = road;
                    if(!arListSites.Contains(road.scanNetworkName)&& road.scanNetworkName!= siteName)
                    {
                        arListSites.Add(road.scanNetworkName);
                    }
                }
                if(arListSites.Count>0)
                {
                    return false;
                }
                if(roadBean.scanNetworkName== siteName&& roadBean.scanTypeName.Contains("发件"))
                {
                    return false;
                }
                
                
               
            }
            catch (Exception ex)
            {

            }
            
            return res;

        }


        public bool isParcelLeaveFirstCenter(ArrayList arListRoadMap,string pickName)
        {
            bool res = false;
            Hashtable htSites = new Hashtable();
            try
            {
                ArrayList arListFilterCenters = new ArrayList();
                string lastCenter = "";
                if(MemberInfo.Instance.htFilterMap.ContainsKey(pickName))
                {
                    string[] arrCenters = MemberInfo.Instance.htFilterMap[pickName].ToString().Split(',');
                    foreach(string center in arrCenters)
                    {
                        arListFilterCenters.Add(center);
                    }
                }
                ArrayList arListCenters = new ArrayList();
                foreach (RoadBean road in arListRoadMap)
                {
                    if (road.scanStieWorkID != "")
                    {
                        htSites[road.scanStieWorkID] = "";
                    }
                    string scanTypeName = road.scanTypeName;
                    if(scanTypeName.Contains("发件"))
                    {
                        if(arListFilterCenters.Contains(road.nextStopName)|| arListFilterCenters.Contains(road.scanNetworkName))
                        {
                            res = true;
                        }

                    }
                    if (road.scanTypeName.Contains("入库"))
                    {
                        res = true;
                    }
                    if (road.scanNetworkName.Contains("中心"))
                    {
                        lastCenter = road.scanNetworkName;
                        if (!arListCenters.Contains(road.scanNetworkName)&& road.scanNetworkName.Length>3)
                        {
                            arListCenters.Add(road.scanNetworkName);
                        }
                        
                    }
                    
                }
                if(arListCenters.Count>1)
                {
                    res = true;
                }
                else if(!arListFilterCenters.Contains(lastCenter)&& lastCenter.Length>2)
                {
                    res = true;
                }
  
            }
            catch (Exception ex)
            {

            }
        
            return res;

        }



        public bool isInCenterMoreThan73Hours(ArrayList arListRoadMap, string siteName,string pickName)
        {
            bool res = false;
            Hashtable htSites = new Hashtable();
            try
            {               
                ArrayList arListCenters = new ArrayList();
                RoadBean curRoad = new RoadBean();
                foreach (RoadBean road in arListRoadMap)
                {
                    if(road.scanNetworkName!=StoParams.Instance.register_site)
                    {
                        curRoad = road;
                    }
                }
                string scanTime = curRoad.scanTime;
                DateTime dtScan = Convert.ToDateTime(scanTime);
                TimeSpan ts = System.DateTime.Now - dtScan;
                if(ts.TotalHours>72&& !siteName.Contains("网点"))
                {
                    res = true;
                }

            }
            catch (Exception ex)
            {

            }

            return res;

        }



        public string getLanShouSite(ArrayList arListRoadMap)
        {
            string res = "";
            try
            {
                foreach(RoadBean roadBean in arListRoadMap)
                {
                    if(roadBean.scanTypeName.Contains("揽收"))
                    {
                        res = roadBean.scanNetworkName;
                        break;
                    }

                }

            }
            catch(Exception ex)
            {

            }
            return res;
        }


        public bool isQianshou(ArrayList arListRoadMap)
        {
            bool res = false;
            try
            {
                for(int i= arListRoadMap.Count-1;i>0;i--)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    if (roadBean.waybillTrackingContent.Contains("签收"))
                    {
                        res = true;
                    }

                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public string getLanShouTime(ArrayList arListRoadMap)
        {
            string res = "";
            try
            {
                foreach (RoadBean roadBean in arListRoadMap)
                {
                    if (roadBean.scanTypeName.Contains("揽收"))
                    {
                        res = roadBean.scanTime;
                        if(res.Contains(" "))
                        {
                            res = res.Substring(0, res.IndexOf(' '));
                        }
                        break;
                    }

                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }







        public bool isYiqingStay(ArrayList arListRoadMap)
        {
            bool res = false;
            Hashtable htSites = new Hashtable();
            try
            {
                if (arListRoadMap.Count < 3)
                {
                    return res;
                }

                RoadBean road = (RoadBean)arListRoadMap[arListRoadMap.Count - 1];
                if (road.scanTypeName.Contains("问题件") && road.waybillTrackingContent.Contains("疫情") )
                {
                    res = true;

                   
                }


            }
            catch (Exception ex)
            {

            }

            return res;

        }

        public bool isLastSiteIsMyself(ArrayList arListRoadMap,out string msg)
        {
            bool res = false;
            msg = "";
            Hashtable htSites = new Hashtable();
            try
            {
                if(arListRoadMap.Count<3)
                {
                    return res;
                }

                string lanshouSite = getLanShouSite(arListRoadMap);
                if(lanshouSite=="")
                {
                    lanshouSite = StoParams.Instance.register_site;
                }
                RoadBean road = (RoadBean)arListRoadMap[arListRoadMap.Count - 1];
                if((road.scanTypeName.Contains("签收")|| road.waybillTrackingContent.Contains("签收")|| road.scanTypeName.Contains("出仓扫描"))
                    &&!road.waybillTrackingContent.Contains("未签收"))
                {
                    if(lanshouSite == road.scanNetworkName)
                    {
                        res = true;
                        msg = "已退回揽收站点";
                    }
                }
                else  if (road.scanTypeName.Contains("到件") )
                {
                    if (lanshouSite == road.scanNetworkName)
                    {
                        res = true;
                        msg = "已退回揽收站点";
                    }
                }
                else if (road.scanTypeName.Contains("出仓扫描"))
                {
                    if (lanshouSite == road.scanNetworkName)
                    {
                        res = true;
                        msg = "已退回揽收站点";
                    }
                }


            }
            catch (Exception ex)
            {

            }

            return res;

        }




        public bool isInterceptButAssigned(ArrayList arListRoadMap, out string msg)
        {
            bool res = false;
            msg = "";
            Hashtable htSites = new Hashtable();
            try
            {
                if (arListRoadMap.Count < 3)
                {
                    return res;
                }

                string lanshouSite = getLanShouSite(arListRoadMap);
                if (lanshouSite == "")
                {
                    lanshouSite = StoParams.Instance.register_site;
                }
                RoadBean road = (RoadBean)arListRoadMap[arListRoadMap.Count - 1];
                if ((road.scanTypeName.Contains("签收") || road.waybillTrackingContent.Contains("签收"))
                    && !road.waybillTrackingContent.Contains("未签收"))
                {
                    if (lanshouSite != road.scanNetworkName)
                    {
                        res = true;
                        msg = "退回失败，已签收";
                    }
                }

                bool isCancel = false;
                foreach(RoadBean roadBean in arListRoadMap)
                {
                    if(roadBean.scanTypeName.Contains("拦截件撤销"))
                    {
                        isCancel = true;
                    }
                    if (roadBean.scanTypeName.Contains("拦截件登记"))
                    {
                        isCancel = false;
                    }
                }
                if(isCancel)
                {
                    res = false;
                }
                /*else if (road.scanTypeName.Contains("到件"))
                {
                    if (lanshouSite == road.scanNetworkName)
                    {
                        res = true;
                        msg = "已退回揽收站点";
                    }
                }
                else if (road.scanTypeName.Contains("出仓扫描"))
                {
                    if (lanshouSite == road.scanNetworkName)
                    {
                        res = true;
                        msg = "已退回揽收站点";
                    }
                }*/


            }
            catch (Exception ex)
            {

            }

            return res;

        }

        public ArrayList getRoadMapByToken(string barcode, out string msg, string token)
        {
            msg = "";
            ArrayList arListAllRoadmap = new ArrayList();
            ArrayList arListGXTask = new ArrayList();
            try
            {
                string queryUrl = " https://jmsgw.jtexpress.com.cn/operatingplatform/podTracking/inner/query/keywordList";

                if (StoParams.Instance.isRabbitWin)
                {
                    queryUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/podTracking/inner/query/keywordList";
                }
                JObject jObj = new JObject();
                JArray jarry = new JArray();
                jObj["current"] = 1;
                jObj["trackingTypeEnum"] = "WAYBILL";
                jObj["countryId"] = "1";
                jarry.Add(barcode);
                jObj["keywordList"] = jarry;
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string res = HttpClient.HttpUtil.Instance.PostCommonByToken(queryUrl, postData, "trackingExpress", token);

                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    string resMsg = jsonObj["msg"].ToString();
                    msg = resMsg;
                    JArray dataArr = (JArray)jsonObj["data"];
                    if (dataArr != null)
                    {
                        JObject jsonDetails = (JObject)dataArr[0];
                        JArray detailsRecords = (JArray)jsonDetails["details"];
                        arListAllRoadmap = UtilityHelp.Instance.getDetailRoadMap(detailsRecords, arListGXTask);
                    }


                }
                else
                {
                    if (res.Contains("未能解析此远程名称"))
                    {
                        msg = "网络域名不通";
                    }
                    else if (res.Contains("远程服务器返回错误: (405) 不允许的方法"))
                    {
                        msg = "认证过期，请重新登录JMS，设置机器人在线";
                    }
                    else
                    {
                        msg = res;
                    }
                    //
                }


            }
            catch (Exception ex)
            {
                if (ex.ToString().Contains("登录"))
                {
                    msg = "请重新登录JMS，并重新授权，设置机器人在线";

                }
            }
            return arListAllRoadmap;
        }


        public ArrayList getRoadMap(string barcode, out string msg, ArrayList arListGXTask)
        {
            msg = "";
            ArrayList arListAllRoadmap = new ArrayList();
            
            arListGXTask = new ArrayList();
            try
            {
                /*string queryUrl = "https://jmsgw.jtexpress.com.cn/servicequality/thirdService/ops/podTrackingList?waybillNos=" + barcode.Trim();
                JObject jObj = new JObject();

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string res = HttpClient.HttpUtil.Instance.QueryCommon(queryUrl, postData, "GET", "arbitrationApply");*/
                string queryUrl = " https://jmsgw.jtexpress.com.cn/operatingplatform/podTracking/inner/query/keywordList";
                if(StoParams.Instance.isRabbitWin)
                {
                    queryUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/podTracking/inner/query/keywordList";
                }
                JObject jObj = new JObject();
                JArray jarry = new JArray();
                jObj["current"] = 1;
                jObj["trackingTypeEnum"] = "WAYBILL";
                jObj["countryId"] = "1";
                jarry.Add(barcode);
                jObj["keywordList"] = jarry;
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string res = HttpClient.HttpUtil.Instance.PostCommon(queryUrl, postData, "trackingExpress");

                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    string resMsg = jsonObj["msg"].ToString();
                    msg = resMsg;
                    JArray dataArr = (JArray)jsonObj["data"];
                    if (dataArr != null)
                    {
                        JObject jsonDetails = (JObject)dataArr[0];
                        JArray detailsRecords = (JArray)jsonDetails["details"];
                        arListAllRoadmap = UtilityHelp.Instance.getDetailRoadMap(detailsRecords, arListGXTask);
                    }


                }
                else
                {
                    if (res.Contains("未能解析此远程名称"))
                    {
                        msg = "网络域名不通";
                    }
                    else if (res.Contains("远程服务器返回错误: (405) 不允许的方法"))
                    {
                        msg = "认证过期，请重新登录JMS，设置机器人在线";
                    }
                    else
                    {
                        msg = res;
                    }
                    //
                }


            }
            catch (Exception ex)
            {
                if (ex.ToString().Contains("登录"))
                {
                    msg = "请重新登录JMS，并重新授权，设置机器人在线";

                }
            }
            return arListAllRoadmap;
        }

        public ArrayList getArbitrationBarcodes(out string  msg)
        {
            msg = "";
            ArrayList arListBarcodes = new ArrayList();
            try
            {
                string startDateTime = System.DateTime.Now.AddDays(-15).ToString("yyyy-MM-dd HH:mm:ss");
                string endDateTime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                string queryUrl = "https://jmsgw.jtexpress.com.cn/servicequality/arbitration/list?size=100&current=1";
                if(StoParams.Instance.isRabbitWin)
                {
                    queryUrl = "https://wdgw.jtexpress.com.cn/servicequality/arbitration/list?size=100&current=1";
                }
                JObject jObj = new JObject();
                jObj["dateType"] = 0;
                jObj["countryId"] = "1";
                jObj["createNetworkId"] = Convert.ToInt32(StoParams.Instance.register_networkId);
                jObj["startDate"] = startDateTime;
                jObj["endDate"] = endDateTime;
                jObj["financeChannel"] = 1;
                jObj["firstId"] = "";
                jObj["secondId"] = "";
                jObj["timeout"] = 25000;
                jObj["type"] = 1;
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string res = HttpClient.HttpUtil.Instance.PostCommon(queryUrl, postData, "arbitrationMyApply");

                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
  
                    JObject dataObj = (JObject)jsonObj["data"];
                    JToken pages = (JToken)dataObj["pages"];
                    int totalPages = Convert.ToInt32(pages.ToString());
                    for(int page=1;page<= totalPages; page++)
                    {
                        System.Threading.Thread.Sleep(200);
                        queryUrl = "https://jmsgw.jtexpress.com.cn/servicequality/arbitration/list?size=100&current="+ page;
                        if (StoParams.Instance.isRabbitWin)
                        {
                            queryUrl = "https://wdgw.jtexpress.com.cn/servicequality/arbitration/list?size=100&current=" + page;
                        }
                        res = HttpClient.HttpUtil.Instance.PostCommon(queryUrl, postData, "arbitrationMyApply");
                        if (res.Contains("data"))
                        {
                            jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                            dataObj = (JObject)jsonObj["data"];
                            JArray records = (JArray)dataObj["records"];
                            for(int i=0;i< records.Count;i++)
                            {
                                JObject curRecord = (JObject)records[i];
                                JToken wayBill = (JToken)curRecord["waybillNo"];
                                if(wayBill!=null)
                                {
                                    if (!arListBarcodes.Contains(wayBill.ToString()))
                                    {
                                        arListBarcodes.Add(wayBill.ToString());
                                    }
                                }                               

                            }

                        }

                    }

                }

                else
                {
                    if (res.Contains("未能解析此远程名称"))
                    {
                        msg = "网络域名不通";
                    }
                    else if (res.Contains("远程服务器返回错误: (405) 不允许的方法"))
                    {
                        msg = "认证过期，请重新登录JMS，设置机器人在线";
                    }
                    else
                    {
                        msg = res;
                    }
                    //
                }



            }
            catch (Exception ex)
            {
                if (ex.ToString().Contains("登录"))
                {
                    msg = "请重新登录JMS，并重新授权，设置机器人在线";

                }
            }
            return arListBarcodes;
        }


        public void getCommentsContent(string barcode, out string msg,out string lastUpdateTime)
        {
            msg = "";
            lastUpdateTime = "";
            ArrayList arListAllRoadmap = new ArrayList();
            try
            {
                string queryUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/messageBoard/list";
                JObject jObj = new JObject();
                jObj["countryId"] = "1";
                jObj["current"] =1;
                jObj["size"] = 1000;
                jObj["waybillNo"] = barcode;

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string res = HttpClient.HttpUtil.Instance.PostCommon(queryUrl, postData, "trackingExpress");
                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    string resMsg = jsonObj["msg"].ToString();
      
                    JArray dataArr = (JArray)jsonObj["data"];
                    if (dataArr != null)
                    {
                        for(int i=0;i< dataArr.Count;i++)
                        {
                            JObject jsonData = (JObject)dataArr[i];
                            string registerNetworkId = jsonData["registerNetworkId"].ToString();
                            string replyContent= jsonData["replyContent"].ToString();
                            
                            if (registerNetworkId== StoParams.Instance.register_networkId)
                            {
                                if(lastUpdateTime=="")
                                {
                                    lastUpdateTime= jsonData["updateTime"].ToString();
                                }
                                if(isContainPayFinish(replyContent))
                                {
                                    msg = "已理赔";
                                    return;
                                }

                                if (isContainReturnParcel(replyContent))
                                {
                                    msg = "退回";
                                    return;
                                }

                            }

                        }
                    }


                }
                else
                {
                    if (res.Contains("未能解析此远程名称"))
                    {
                        msg = "网络域名不通";
                    }
                    else if (res.Contains("远程服务器返回错误: (405) 不允许的方法"))
                    {
                        msg = "认证过期，请重新登录JMS，设置机器人在线";
                    }
                    else
                    {
                        msg = res;
                    }
                    //
                }


            }
            catch (Exception ex)
            {
                if (ex.ToString().Contains("登录"))
                {
                    msg = "请重新登录JMS，并重新授权，设置机器人在线";

                }
            }
        }


        public bool isContainPayFinish(string content)
        {
            if((content.Contains("已收到理赔") || content.Contains("已理赔")|| content.Contains("理赔完成"))&&!content.Contains("如已"))
            {
                return true;
            }
            /*else if (content.Contains("理赔")&&content.Contains("已")&& !content.Contains("如已") && !content.Contains("如果已"))
            {
                return true;
            }
            else if (content.Contains("赔偿") && content.Contains("已") && !content.Contains("如已") && !content.Contains("如果已"))
            {
                return true;
            }*/
            return  false;

        }


        public bool isContainReturnParcel(string content)
        {
            if (content.Contains("退回") || content.Contains("退件"))
            {
                return true;
            }
           
            return false;

        }


        public JObject getWayBillDetail(string barcode, out string msg)
        {
            JObject jObj = new JObject();
            msg = "";
            ArrayList arListAllRoadmap = new ArrayList();
            try
            {
                /*string queryUrl = "https://jmsgw.jtexpress.com.cn/servicequality/thirdService/ops/podTrackingList?waybillNos=" + barcode.Trim();
                JObject jObj = new JObject();

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string res = HttpClient.HttpUtil.Instance.QueryCommon(queryUrl, postData, "GET", "arbitrationApply");*/
                string queryUrl = " https://jmsgw.jtexpress.com.cn/operatingplatform/rebackTransferExpress/findByWaybillNo?waybillNo="+ barcode.Trim() + "&applyTypeCode=5";
                if (StoParams.Instance.isRabbitWin)
                {

                    queryUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/rebackTransferExpress/findByWaybillNo?waybillNo=" + barcode.Trim() + "&applyTypeCode=5";
                }
                JArray jarry = new JArray();
                jarry.Add(barcode);
                jObj["keywordList"] = jarry;
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string res = HttpClient.HttpUtil.Instance.QueryCommon(queryUrl, postData, "GET", "returnAndForwardMaintainAddSite");

                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    string resMsg = jsonObj["msg"].ToString();
                    msg = resMsg;
                    jObj = (JObject)jsonObj["data"];

                }
                else
                {
                    if (res.Contains("未能解析此远程名称"))
                    {
                        msg = "网络域名不通";
                    }
                    else if (res.Contains("远程服务器返回错误: (405) 不允许的方法"))
                    {
                        msg = "认证过期，请重新登录JMS，设置机器人在线";
                    }
                    else
                    {
                        msg = res;
                    }
                    //
                }


            }
            catch (Exception ex)
            {
                if (ex.ToString().Contains("登录"))
                {
                    msg = "请重新登录JMS，并重新授权，设置机器人在线";

                }
            }
            return jObj;

        }


        public JObject getInfoByAddr(string addr, out string msg)
        {
            JObject jObj = new JObject();
            msg = "";
            ArrayList arListAllRoadmap = new ArrayList();
            try
            {
                /*string queryUrl = "https://jmsgw.jtexpress.com.cn/servicequality/thirdService/ops/podTrackingList?waybillNos=" + barcode.Trim();
                JObject jObj = new JObject();

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string res = HttpClient.HttpUtil.Instance.QueryCommon(queryUrl, postData, "GET", "arbitrationApply");*/
                string queryUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/ocrAddress/getInfoByAddress";

                if (StoParams.Instance.isRabbitWin)
                {
                    queryUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/ocrAddress/getInfoByAddress";
                }
                JObject curObg = new JObject();

                curObg["addressContent"] = addr;
                curObg["countryId"] = "1";


                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(curObg);
                string res = HttpClient.HttpUtil.Instance.PostCommon(queryUrl, postData, "returnAndForwardMaintainAddSite");


                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    string resMsg = jsonObj["msg"].ToString();
                    msg = resMsg;
                    jObj = (JObject)jsonObj["data"];


                }
                else
                {
                    if (res.Contains("未能解析此远程名称"))
                    {
                        msg = "网络域名不通";
                    }
                    else if (res.Contains("远程服务器返回错误: (405) 不允许的方法"))
                    {
                        msg = "认证过期，请重新登录JMS，设置机器人在线";
                    }
                    else
                    {
                        msg = res;
                    }
                    //
                }


            }
            catch (Exception ex)
            {
                if (ex.ToString().Contains("登录"))
                {
                    msg = "请重新登录JMS，并重新授权，设置机器人在线";

                }
            }
            return jObj;

        }



        public JObject getProvince(string provinceCode, string msg)
        {
            JObject jObj = new JObject();
            msg = "";
            ArrayList arListAllRoadmap = new ArrayList();
            try
            {             
                string queryUrl = " https://jmsgw.jtexpress.com.cn/basicdata/sysArea/select?type=2&size=99999999";
                if (StoParams.Instance.isRabbitWin)
                {
                    queryUrl = "https://wdgw.jtexpress.com.cn/basicdata/sysArea/select?type=2&size=99999999";
                }

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string res = HttpClient.HttpUtil.Instance.QueryCommon(queryUrl, postData, "GET", "returnAndForwardMaintainAddSite");

                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    string resMsg = jsonObj["msg"].ToString();
                    msg = resMsg;
                    JObject dataObj = (JObject)jsonObj["data"];
                    JArray records = (JArray)dataObj["records"];
                    for (int i = 0; i < records.Count; i++)
                    {
                        JObject curObj = (JObject)records[i];
                        string code = curObj["code"].ToString();
                        if(code== provinceCode)
                        {
                            jObj = (JObject)curObj.DeepClone();
                        }
                    }

                }
                else
                {
                    if (res.Contains("未能解析此远程名称"))
                    {
                        msg = "网络域名不通";
                    }
                    else if (res.Contains("远程服务器返回错误: (405) 不允许的方法"))
                    {
                        msg = "认证过期，请重新登录JMS，设置机器人在线";
                    }
                    else
                    {
                        msg = res;
                    }
                    //
                }


            }
            catch (Exception ex)
            {
                if (ex.ToString().Contains("登录"))
                {
                    msg = "请重新登录JMS，并重新授权，设置机器人在线";

                }
            }
            return jObj;

        }



        public JObject getCity(string provinceCode, string cityCode, string msg)
        {
            JObject jObj = new JObject();
            msg = "";
            ArrayList arListAllRoadmap = new ArrayList();
            try
            {
                string queryUrl = " https://jmsgw.jtexpress.com.cn/basicdata/sysArea/select?parentId="+ provinceCode + "&size=99999999";
                if (StoParams.Instance.isRabbitWin)
                {
                    queryUrl = "https://wdgw.jtexpress.com.cn/basicdata/sysArea/select?parentId=" + provinceCode + "&size=99999999";
                }


                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string res = HttpClient.HttpUtil.Instance.QueryCommon(queryUrl, postData, "GET", "returnAndForwardMaintainAddSite");

                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    string resMsg = jsonObj["msg"].ToString();
                    msg = resMsg;
                    JObject dataObj = (JObject)jsonObj["data"];
                    JArray records = (JArray)dataObj["records"];
                    for (int i = 0; i < records.Count; i++)
                    {
                        JObject curObj = (JObject)records[i];
                        string code = curObj["code"].ToString();
                        if (code == cityCode)
                        {
                            jObj = (JObject)curObj.DeepClone();
                        }
                    }

                }
                else
                {
                    if (res.Contains("未能解析此远程名称"))
                    {
                        msg = "网络域名不通";
                    }
                    else if (res.Contains("远程服务器返回错误: (405) 不允许的方法"))
                    {
                        msg = "认证过期，请重新登录JMS，设置机器人在线";
                    }
                    else
                    {
                        msg = res;
                    }
                    //
                }


            }
            catch (Exception ex)
            {
                if (ex.ToString().Contains("登录"))
                {
                    msg = "请重新登录JMS，并重新授权，设置机器人在线";

                }
            }
            return jObj;

        }


        public JObject getArea(string cityCode, string townCode, string msg,string townName)
        {
            JObject jObj = new JObject();
            msg = "";
            ArrayList arListAllRoadmap = new ArrayList();
            try
            {
                string queryUrl = " https://jmsgw.jtexpress.com.cn/basicdata/sysArea/select?parentId=" + cityCode + "&size=99999999";
                if (StoParams.Instance.isRabbitWin)
                {
                    queryUrl = "https://wdgw.jtexpress.com.cn/basicdata/sysArea/select?parentId="+ cityCode + "&size=99999999";
                }
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string res = HttpClient.HttpUtil.Instance.QueryCommon(queryUrl, postData, "GET", "returnAndForwardMaintainAddSite");

                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    string resMsg = jsonObj["msg"].ToString();
                    msg = resMsg;
                    JObject dataObj = (JObject)jsonObj["data"];
                    JArray records = (JArray)dataObj["records"];
                    bool findCode = false;
                    for (int i = 0; i < records.Count; i++)
                    {
                        JObject curObj = (JObject)records[i];
                        string code = curObj["code"].ToString();
                        if (code == townCode)
                        {
                            findCode = true;
                            jObj = (JObject)curObj.DeepClone();
                        }
                    }
                    if(!findCode)
                    {
                        for (int i = 0; i < records.Count; i++)
                        {
                            JObject curObj = (JObject)records[i];
                            string cnName = curObj["cnName"].ToString();
                            if (cnName == townName)
                            {
                                findCode = true;
                                jObj = (JObject)curObj.DeepClone();
                            }
                        }
                    }

                }
                else
                {
                    if (res.Contains("未能解析此远程名称"))
                    {
                        msg = "网络域名不通";
                    }
                    else if (res.Contains("远程服务器返回错误: (405) 不允许的方法"))
                    {
                        msg = "认证过期，请重新登录JMS，设置机器人在线";
                    }
                    else
                    {
                        msg = res;
                    }
                    //
                }


            }
            catch (Exception ex)
            {
                if (ex.ToString().Contains("登录"))
                {
                    msg = "请重新登录JMS，并重新授权，设置机器人在线";

                }
            }
            return jObj;

        }





        public string getWeightByRoad(ArrayList arListRoadmap,out string pickSite)
        {
            pickSite = "";
            string res = "0";
            try
            {
                double weight = 0;
                string strWeight = "0";
                foreach (RoadBean bean in arListRoadmap)
                {
                    if(bean.weight!="")
                    {
                        try
                        {
                            double dCur = Convert.ToDouble(bean.weight);
                            if(dCur> weight)
                            {
                                weight = dCur;
                                strWeight = bean.weight;
                                res = strWeight;
                            }
                        }
                        catch(Exception ex)
                        {

                        }
                    }
                    if(bean.scanTypeName.Contains("揽收"))
                    {
                        pickSite = bean.scanNetworkName;
                    }
                }



            }
            catch (Exception ex)
            {

            }

            return res;
        }


        public bool isLastRoadIsInterCeptReturn(ArrayList arListRoadMap)
        {
            bool res = false;
            try
            {
                
                //ArrayList arListRoadMap = JTDelayHelper.Instance.getRoadMap(barcode, out httpRes, arListAllGXTask);
                if(arListRoadMap.Count==0)
                {
                    return res;
                }
     
                RoadBean lastRoadBean = (RoadBean)arListRoadMap[arListRoadMap.Count - 1];
                if(lastRoadBean.scanTypeName== "拦截件登记"&& lastRoadBean.waybillTrackingContent.Contains("退回件"))
                {
                    res = true;
                }
                
            }
            catch(Exception ex)
            {

            }
            return res;

        }


        public bool canChageAddr(ArrayList arListRoadMap, out string jisanSite)
        {
            bool res = false;
            jisanSite = "";
            try
            {
                /*if((StoParams.Instance.register_site.Contains("后宅")|| 
                    StoParams.Instance.register_site.Contains("阳江") ||
                    StoParams.Instance.register_site.Contains("和顺")||                    
                    StoParams.Instance.register_site.Contains("东升")||
                    StoParams.Instance.register_site.Contains("百安") ||
                    StoParams.Instance.register_site.Contains("沙溪") ||
                    StoParams.Instance.register_site.Contains("江门") ||
                    StoParams.Instance.register_site.Contains("佛山南海邓岗网点") ||                    
                    StoParams.Instance.register_site.Contains("沙朗隆平")||
                    StoParams.Instance.register_site.Contains("石岐南") ||
                    StoParams.Instance.register_site.Contains("太和") ||
                     StoParams.Instance.register_site.Contains("太和") ||
                    StoParams.Instance.register_site.Contains("沙溪镇")) && MemberInfo.Instance.htFilterMap.ContainsKey(StoParams.Instance.register_site))*/
                if(MemberInfo.Instance.htFilterMap.ContainsKey(StoParams.Instance.register_site))
                {
                    string nextStoName = MemberInfo.Instance.htFilterMap[StoParams.Instance.register_site].ToString();
                    jisanSite = nextStoName;
                    for (int i = 0; i < arListRoadMap.Count; i++)
                    {
                        RoadBean curRoad = (RoadBean)arListRoadMap[i];
                        string scanTypeName = curRoad.scanTypeName;
                        if (scanTypeName != null && (scanTypeName.ToString().Contains("发件")))
                        {
                            if(curRoad.scanNetworkName!=null&& nextStoName.Contains(curRoad.scanNetworkName))
                            {
                                TimeSpan ts = System.DateTime.Now - Convert.ToDateTime(curRoad.scanTime);
                                if(ts.TotalMinutes>10)
                                {
                                    res = true;
                                }
                                
                            }
                        }
                    }
                    if(!res)
                    {
                        ArrayList arListCenters = new ArrayList();
                        ArrayList arListSite = new ArrayList();
                        for (int i = 0; i < arListRoadMap.Count; i++)
                        {
                            RoadBean curRoad = (RoadBean)arListRoadMap[i];
                            string scanTypeName = curRoad.scanTypeName;
                            if (curRoad.scanNetworkName != null && (curRoad.scanNetworkName.Contains("转运中心") || curRoad.scanNetworkName.Contains("分拨")))
                            {
                                
                                if(!arListCenters.Contains(curRoad.scanNetworkName))
                                {
                                    arListCenters.Add(curRoad.scanNetworkName);
                                }
                                if(arListRoadMap.Count>4&&curRoad.nextStopName.Contains("网点")&& curRoad.nextStopName!= StoParams.Instance.register_site)
                                {
                                    if (!arListSite.Contains(curRoad.nextStopName))
                                    {
                                        arListSite.Add(curRoad.nextStopName);
                                    }
                                }
                            }

                            if (scanTypeName != null && (scanTypeName.ToString().Contains("发件")))
                            {
                                if (curRoad.scanNetworkName != null && (curRoad.nextStopName.Contains("转运中心")|| curRoad.nextStopName.Contains("分拨")))
                                {
                                    if(curRoad.nextStopName!= nextStoName)
                                    {
                                        res = true;
                                    }
                                    
                                }
                            }
                        }
                        if(arListCenters.Count>1)
                        {
                            res = true;
                        }
                        else if(arListCenters.Count==1)
                        {
                            string center = arListCenters[0].ToString();
                            if(!nextStoName.Contains(center))
                            {
                                res = true;
                            }
                        }

                        if(!res)
                        {
                            if(arListSite.Count>0)
                            {
                                res = true;
                            }
                        }

                    }

                        

                }
                else
                {
                    res = true;
                }

            }
            catch (Exception ex)
            {

            }
            return res;

        }


       








    }
}
